$phone, // 'code' => $code, // 'state' => 0, // 'purpose' => 'activity_phone_code', // 'effective_time' => time() + 60 * 5 // ]; // Sms::create($data); // sendSms($phone, $code); // return json(['code' => 0, 'vecode' => $code]); // } public function mini($id, $type) { $token = request()->token; $appid = config("app.$token[client_type].mini_appid"); $data = $this->pay($appid, $type, $id); return json($data); } private function pay($appid, $type, $id) { $order = $this->$type($id); if (isset($order['code'])) return $order; $typeArr = [ 'handanyijing' => 'hdyj', 'xinjushang' => 'xjs' ]; if (!isset($typeArr[$order['mch']])) return ['code' => self::error_debug_msg, 'msg' => $order['mch'] . '支付账户不存在']; $type = $typeArr[$order['mch']]; // 获取配置信息 $config = [ 'app_id' => $appid, 'mch_id' => config("app.$type.mch_id"), 'key' => config("app.$type.mch_key"), ]; $param = wxJsapiPay($config, $order, $this->request->token['openid']); return ['code' => self::success, 'data' => $param]; } private function activity($id) { $param = $this->request->param(['name', 'phone']); // $param = $this->request->param(['name', 'phone', 'vecode']); // if (empty($param['name']) || empty($param['phone'])) // return ['code' => self::error_msg, 'msg' => '请输入姓名和手机号']; // 验证手机号验证码 // $sms = Sms::where(['phone' => $param['phone'], 'code' => $param['vecode'], 'purpose' => 'activity_phone_code', 'state' => 0])->find(); // if (empty($sms)) return ['code' => self::error_msg, 'msg' => '验证码错误']; // $sms->state = 1; // $sms->save(); $today = date('Y-m-d'); // 查询活动,获取活动金额 $activity = Activity::where([['start_date', '<=', $today], ['end_date', '>=', $today]])->find($id); if (empty($activity)) return ['code' => self::error_msg, 'msg' => '活动未开始或已结束']; if ($activity->money <= 0) return ['code' => self::error_msg, 'msg' => '无需支付']; // if ($this->request->token['isEmployee']) // return ['code' => self::error_msg, 'msg' => '员工无需参加该活动']; if (empty($activity->wxmch)) return ['code' => self::error_msg, 'msg' => '未设置支付账户']; // 重复交定排查 $hadPay = ActivityOrder::where(['user_id' => $this->request->token['uid'], 'activity_id' => $id, 'state' => 1])->count(); if ($hadPay) return ['code' => self::error_msg, 'msg' => '请勿重复交定']; // 查找该客户所属客户 $belongsToEmployee = Customer::where(['uid' => $this->request->token['uid']])->value('employee_id'); $activityOrder = ActivityOrder::create([ 'order_no' => date('YmdHis') . rand(100000, 999999), 'money' => $activity['money'], 'user_id' => $this->request->token['uid'], 'addtime' => time(), 'activity_id' => $activity->id, 'employee_id' => $belongsToEmployee, 'share_employee_id' => $this->request->share_employee, 'state' => 0, 'account' => $activity->wxmch, 'name' => $param['name'], 'phone' => $param['phone'] ]); $mchType = $activity->wxmch; return [ 'mch' => $mchType, 'orderNo' => $activityOrder->order_no, 'money' => $activityOrder->money, 'body' => '《' . $activity->title . '》活动定金支付', 'attach' => 'activityOrder', 'notifyUrl' => url('client/wxNotify/' . $mchType . 'Mini', [], true, true), ]; } }