在提交注册信息的时候报错:
"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'a3b6420a-6724-11ea-b2a3-d773d1d6999f' for key 'callId'\nThe SQL being executed was: INSERT INTO `ly_call` (`call_id`, `mobile`, `call_method`, `call_type`, `origin_mobile`, `status`, `call_status`, `type`, `customer_id`, `area`, `answer_id`, `department`, `is_frontend`, `created_at`, `updated_at`) VALUES ('a3b6420a-6724-11ea-b2a3-d773d1d6999f', '13825795639', 5, 0, '013825795639', 0, 0, 2, '0', '广东东莞', 100604121, 10179, 2, 1584321766, 1584321766)"
原因:主键冲突
从上图可以看出,callId必须唯一,如果填入重复的callId就会出错
解决方法:在控制器里面进行判断
TP5写法
$data = input('post.');
$callId = model('LyCall')->get(['callId'=>$data['callId']]);
if(sizeof($callId)){
$this->error('该用户名已经拨打,请重新填写~~~');
}
Yii2.0写法
$callId= Yii::$app->request->post('callId');
$info = LyCall::findOne(['callId'=>$callId]);
if (!empty($info)) {
throw new LyException($callId . '已经存在!');
}
添加上面代码之后,如果拨打电话,重复callId就会给用户相关提示~~~