store_id; if (\Yii::$app->request->isGet) { // $userAuditSetting = UserAuditSetting::findOne(['store_id' => $store_id]); $data = [ 'id' => $userAuditSetting->id ?? 0, 'status' => (int)$userAuditSetting->status ?? 0, 'bg_image' => $userAuditSetting->bg_image ?? '', 'form_name' => $userAuditSetting->form_name ?? '', 'form_list' => json_decode($userAuditSetting->custom_form, true) ?? null, 'protocol' => $userAuditSetting->protocol ?? '', 'wx_b2b_pay_open' => $userAuditSetting->wx_b2b_pay_open ?? 0, 'wx_b2b_pay_mchid' => $userAuditSetting->wx_b2b_pay_mchid ?? '', ]; return [ 'code' => 0, 'msg' => '获取成功', 'mchorder' => B2bPay::mchorder($store_id), 'data' => $data + ($userAuditSetting ? $userAuditSetting->toArray() : []), ]; } else { $post = all_params(); $status = $this->status; $bg_image = $this->bg_image; $form_name = $this->form_name; $custom_form = $this->form_list; $protocol = $this->protocol; if (!empty($custom_form)) { $custom_form = json_decode($custom_form, true); if (!empty($custom_form)) { foreach ($custom_form as $custom) { if (!isset($custom['name'])) { throw new \Exception('自定义表单缺少名称'); } if (!isset($custom['required'])) { throw new \Exception('自定义表单缺少是否必填项'); } if (!isset($custom['tip'])) { throw new \Exception('自定义表单缺少提示信息'); } if (!isset($custom['type'])) { throw new \Exception('自定义表单缺少类型'); } } $custom_form = json_encode($custom_form, JSON_UNESCAPED_UNICODE); } else { $custom_form = null; } } $userAuditSetting = UserAuditSetting::findOne(['store_id' => $store_id]); if (!$userAuditSetting) { $userAuditSetting = new UserAuditSetting(); $userAuditSetting->store_id = $store_id; } $userAuditSetting->status = $status; $userAuditSetting->bg_image = $bg_image; $userAuditSetting->form_name = $form_name; $userAuditSetting->custom_form = $custom_form; $userAuditSetting->protocol = $protocol; if($post['wx_b2b_pay_mchid'] && $userAuditSetting->wx_b2b_pay_mchid != $post['wx_b2b_pay_mchid']){ $b2bPayUpdate = 1; } isset($post['wx_b2b_pay_open']) && $userAuditSetting->wx_b2b_pay_open = (int)$post['wx_b2b_pay_open']; isset($post['wx_b2b_pay_mchid']) && $userAuditSetting->wx_b2b_pay_mchid = trim($post['wx_b2b_pay_mchid']); if (!$userAuditSetting->save()) { throw new \Exception('保存失败' . json_encode($userAuditSetting->errors, JSON_UNESCAPED_UNICODE)); } $b2bPayUpdate && $b2bPayUpdate = B2bPay::setmchprofitrate($store_id, B2bPay::getMinProfitRate()); return [ 'code' => 0, 'b2bPayUpdate' => $b2bPayUpdate, 'mchorder' => B2bPay::mchorder($store_id), 'msg' => '操作成功' ]; } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //用户审核列表 public function userAuditList() { $nickname = $this->nickname; $mobile = $this->mobile; $start_time = $this->start_time; $end_time = $this->end_time; $audit_start_time = $this->audit_start_time; $audit_end_time = $this->audit_end_time; $status = $this->status; $id = $this->id; $query = UserAuditLog::find()->alias('ual') ->leftJoin(['u' => User::tableName()], 'u.id = ual.user_id') ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile = u.binding') ->where(['ual.store_id' => $this->store_id, 'ual.is_delete' => 0]); // ->andWhere(['AND', ['IS NOT', 'u.id', null], ['IS NOT', 'su.id', null]]); if (!empty($id)) { $query->andWhere(['ual.id' => $id]); } if (!empty($nickname)) { $query->andWhere(['like', 'su.name', $nickname]); } if (!empty($mobile)) { $query->andWhere(['like', 'su.mobile', $mobile]); } if (!empty($start_time)) { $query->andWhere(['>=', 'ual.created_at', strtotime($start_time)]); } if (!empty($end_time)) { $query->andWhere(['<=', 'ual.created_at', strtotime($end_time)]); } if (!empty($audit_start_time)) { $query->andWhere(['>=', 'ual.audit_time', strtotime($audit_start_time)]); } if (!empty($audit_end_time)) { $query->andWhere(['<=', 'ual.audit_time', strtotime($audit_end_time)]); } if ($status !== null && in_array($status, [0, 1, 2])) { $query->andWhere(['ual.status' => $status]); } $query->orderBy('ual.id DESC'); $query->select('ual.id, su.name nickname, su.mobile, ual.avatar, ual.status, ual.audit_time, ual.created_at, ual.pass_remark, ual.custom_form, ual.user_id'); $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item['audit_time'] = $item['audit_time'] ? date('Y-m-d H:i:s', $item['audit_time']) : '-'; $item['created_at'] = $item['created_at'] ? date('Y-m-d H:i:s', $item['created_at']) : ''; $item['custom_form'] = json_decode($item['custom_form'], true); $item['status'] = (int)$item['status']; if (!$item['user_id'] || !$item['mobile']) { $item['nickname'] = '-'; $item['mobile'] = '-'; } } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]; } //用户审核拒绝/同意/删除 public function userAuditStatus() { try { $ids = $this->ids; $status = intval($this->status); $pass_remark = $this->pass_remark; if (!empty($ids)) { $ids = explode(',', $ids); } if (empty($ids)) { throw new \Exception('请选择用户审核记录'); } if (!in_array($status, [1, 2, 3])) { throw new \Exception('状态错误'); } foreach ($ids as $id) { $userAuditLog = UserAuditLog::findOne(['id' => $id, 'is_delete' => 0]); if (!$userAuditLog) { throw new \Exception('审核记录查询失败'); } //通过/拒绝 if (in_array($status, [1, 2])) { if ($userAuditLog->status !== 0) { throw new \Exception('审核记录不可重复操作'); } if ($status === 2 && empty($pass_remark)) { throw new \Exception('拒绝请填写审核内容'); } $userAuditLog->status = $status;; $userAuditLog->pass_remark = ''; $userAuditLog->audit_time = (string)time(); if ($status === 2) { $userAuditLog->pass_remark = $pass_remark; } } else { $userAuditLog->is_delete = 1; } if (!$userAuditLog->save()) { throw new \Exception(json_encode($userAuditLog->errors, JSON_UNESCAPED_UNICODE)); } if ($status === 1) { $user = User::findOne(['id' => $userAuditLog->user_id]); if (!empty($user)) { if (!empty($userAuditLog->avatar)) { $user->avatar_url = $userAuditLog->avatar; if (!$user->save()) { throw new \Exception(json_encode($user->errors, JSON_UNESCAPED_UNICODE)); } } $saasUser = SaasUser::findOne(['mobile' => $user->binding]); if (!empty($saasUser)) { if (!empty($userAuditLog->avatar)) { $saasUser->avatar = $userAuditLog->avatar; if (!$saasUser->save()) { throw new \Exception(json_encode($saasUser->errors, JSON_UNESCAPED_UNICODE)); } } } } } } return [ 'code' => 0, 'msg' => '操作成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public static function pay($session_key, $order, $type, $goods_names = null, $balance_price = 0) { try { $store_id = $order->store_id; // $user = UserAuditLog::findOne(['user_id' => $order->user_id, 'is_delete' => 0, 'status' => UserAuditLog::STATUS_AGREE]); // if(!$user){ // throw new \Exception('b2b用户状态异常'); // } $userAuditSetting = UserAuditSetting::findOne(['store_id' => $store_id]); if(!$userAuditSetting['wx_b2b_pay_open']){ throw new \Exception('未启用B2b门店助手支付'); } // $session_key = 'QEjRQCmLrKV+bU+0X7ebuw=='; $pay = B2bPay::pay($session_key, $order, $type, $goods_names, $balance_price); return $pay; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }