mall_id,$user_id,TaxUserAuth::STATUS_OK); return empty($user) ? true : false; } /** * 生成实名链接,成功会返回实名认证url,跳转进行实名 * @param int $user_id 用户ID * @param int $name 姓名 * @param int $mobile 手机号码 * @return bool|string 授权url */ public function goToAuth(int $user_id,string $name,string $mobile) { $api = new SocialApi(); // 回调地址 $url = \Yii::$app->services->setting->platform->get('system.api_url')."/avoid-tax/notify/user-auth"; $param = [ 'mall_user_id' => $this->mall_id .'_'.$user_id, ]; $callback = $url .'?'. http_build_query($param); // 调用api接口 list($res,$auth_url) = $api->userAuth($name,$mobile,$callback); if($res){ // 添加授权用户 TaxUserAuth::addAuthUser($this->mall_id,$user_id,$auth_url); return $auth_url; } \Yii::debug("avoidtax goToAuth err ".$auth_url); return $this->error($auth_url); } /** * 实名认证异步回调 * @ApiResponse(code="500", template="error") * @ApiResponse(code="200", template="success") */ public function authNotify(array $data) { // {"name":"杨金成","id_card_no":"450121199206190092","id_card_front":"","id_card_back":"","mobile":"13923698558","user_id":"751937135803633664"} $malluserid = $data['mall_user_id'] ?? ''; $name = $data['name'] ?? ''; // 姓名 $id_card_no = $data['id_card_no'] ?? ''; // 身份证 $mobile = $data['mobile'] ?? ''; // 手机号码 $workuser_id= $data['user_id'] ?? ''; // list($mall_id,$user_id) = explode('_',$malluserid); if(empty($user_id) || empty($name) || empty($id_card_no)) { \Yii::debug("avoidtax authNotify 参数错误 "); \Yii::debug(Json::encode($data)); return $this->error(" 参数错误 "); } $user = TaxUserAuth::find()->where(['user_id'=>$user_id,'mall_id'=>$mall_id])->one(); if(empty($user)) { \Yii::debug("avoidtax authNotify err " . "user_id 记录不存 "); \Yii::debug(Json::encode($data)); $this->error(" user_id 记录不存 "); } return TaxUserAuth::authOk($user->id,$name,$id_card_no,$mobile,$workuser_id); } /** * 创建发放订单 * 只支持单笔 * @ApiResponse(code="500", template="error") * @ApiResponse(code="200", template="success") * @param array $data * * @return array|bool */ public function createOrder($tax_batch_num) { $api = new SocialApi(); $orders = TaxOrder::find()->with('userAuth')->where(['batch_num'=>$tax_batch_num])->all(); // 创建订单 list ( $res,$job_id ) = $api->createOrder($tax_batch_num); if ( !$res ) return $this->error($job_id); // var_dump($job_id); // $job_id = "753709199636041728"; // 添加批次 $batch_user = []; foreach ( $orders as $item ) { $one['job_name'] = "销售佣金"; // 任务名称 $one['job_no'] = $item['batch_num']; // 任务名称 $one['total_salary'] = $item['amount'];// 总金额 $one['salary'] = $item['amount'];// 金额 // 实名信息 $one['user_name'] = $item->userAuth->name; $one['user_mobile'] = $item->userAuth->mobile; $one['id_card_no'] = $item->userAuth->id_card_no; // 支付宝信息 // $one['bank_name'] = "支付宝"; // $one['bank_card'] = $item['account_num']; $one['bank_name'] = "工商银行"; $one['bank_card'] = "6212263602070285796"; $batch_user[] = $one; } // 往批次号添加明细 // echo json_encode($batch_user); $resp = $api->createOrderDetail($job_id,$batch_user); // echo json_encode($resp); // 失败情况 // $resp = '{"items":[{"user_name":"","user_mobile":"","id_card_no":"","bank_card":"","total_salary":"","status":"f","id":"","err_msg":"totalSalary(任务金额)格式不正确","extra":"","real_total_salary":""}],"err_msg":null}'; // // 成功请求 // $resp = '{"items":[{"user_name":"123","user_mobile":"15820232740","id_card_no":"450121199206190092","bank_card":"15820232749","total_salary":"1.00","status":"s","id":"753709201569615872","err_msg":"","extra":"","real_total_salary":""}],"err_msg":null}'; // $resp = Json::decode($resp); foreach ($resp['items'] as $item) { if($item['status'] != SocialApi::ORDER_SUCCESS){ // 失败 TaxOrder::changStatus($tax_batch_num,[ 'status' => StatusEnum::STATUS_FAIL, 'error' => $item['err_msg'], ]); return $this->error($item['err_msg']); } // 成功 TaxOrder::changStatus($tax_batch_num,[ 'status' => StatusEnum::STATUS_IS_SUBMIT, 'job_id' => $job_id, 'job_detail_id' => $item['id'], ]); } return true; } /** * 订单添加详情 * @ApiResponse(code="500", template="error") * @ApiResponse(code="200", template="success") */ public function addOrderDetail(int $order_id,array $detail_date = []):array { return []; } }