From 074e8ce1a8fb04700912896b749eb85c266a4d35 Mon Sep 17 00:00:00 2001 From: gcd Date: Thu, 27 Mar 2025 22:30:36 +0800 Subject: [PATCH 01/35] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config.php b/application/config.php index 4582b2d..ff8ca5e 100755 --- a/application/config.php +++ b/application/config.php @@ -312,7 +312,7 @@ return [ //插件纯净模式,插件启用后是否删除插件目录的application、public和assets文件夹 'addon_pure_mode' => true, //允许跨域的域名,多个以,分隔 - 'cors_request_domain' => 'localhost,127.0.0.1', + 'cors_request_domain' => 'localhost,127.0.0.1,chrome-extension://gahjcfmabepcnfmfanjhcobdaalgpjoh', //版本号 'version' => '1.5.3.20250217', //API接口地址 From 711a54eb0f84dbbf6732f23466ef01d3cf2be2e3 Mon Sep 17 00:00:00 2001 From: gcd Date: Thu, 27 Mar 2025 22:41:43 +0800 Subject: [PATCH 02/35] =?UTF-8?q?=E5=BC=95=E5=85=A5=20container=20?= =?UTF-8?q?=E3=80=81=E4=B8=80=E9=94=AE=E7=94=9F=E6=88=90=20Controller?= =?UTF-8?q?=E3=80=81Model=E3=80=81Service=20=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 64a383d..77cba9a 100755 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "ext-pdo": "*", "ext-bcmath": "*", "txthinking/mailer": "^2.0", - "symfony/var-dumper": "^6.4" + "symfony/var-dumper": "^6.4", + "gjc/thinkphp5-container": "^1.0.1" }, "config": { "preferred-install": "dist", From dd1fac2198247d7422ab8131891da8e2309bdf28 Mon Sep 17 00:00:00 2001 From: gcd Date: Fri, 28 Mar 2025 00:35:18 +0800 Subject: [PATCH 03/35] =?UTF-8?q?env=20=E5=A2=9E=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E9=85=8D=E7=BD=AE=E3=80=81=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20API=20=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E3=80=81=E5=B8=88?= =?UTF-8?q?=E5=82=85=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=99=BB=E5=BD=95=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.sample | 4 ++ application/api/controller/Worker.php | 22 +++++++++ application/api/library/ApiException.php | 52 +++++++++++++++++++++ application/api/library/ExceptionHandle.php | 5 ++ application/api/validate/Worker.php | 20 ++++++++ application/common/controller/Api.php | 3 +- application/common/model/Worker.php | 18 +++++++ application/config.php | 4 ++ application/services/BaseService.php | 39 ++++++++++++++++ application/services/WorkerService.php | 30 ++++++++++++ 10 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 application/api/controller/Worker.php create mode 100644 application/api/library/ApiException.php create mode 100644 application/api/validate/Worker.php create mode 100644 application/common/model/Worker.php create mode 100644 application/services/BaseService.php create mode 100644 application/services/WorkerService.php diff --git a/.env.sample b/.env.sample index ccd0f29..214e5d6 100755 --- a/.env.sample +++ b/.env.sample @@ -9,3 +9,7 @@ username = root password = root hostport = 3306 prefix = fa_ + +[mini_program] +app_id = +secret = diff --git a/application/api/controller/Worker.php b/application/api/controller/Worker.php new file mode 100644 index 0000000..70aa643 --- /dev/null +++ b/application/api/controller/Worker.php @@ -0,0 +1,22 @@ +request->request(); + $validate = $this->validate($params, \app\api\validate\Worker::class . '.phoneLogin'); + if ($validate !== true) { + $this->error($validate); + } + + $this->success('登录成功', $this->getWorkerService()->phoneLogin($params['code'])); + } +} diff --git a/application/api/library/ApiException.php b/application/api/library/ApiException.php new file mode 100644 index 0000000..1950fda --- /dev/null +++ b/application/api/library/ApiException.php @@ -0,0 +1,52 @@ +getMessage(), + $code->getFile(), + $code->getLine(), + ]); + $code = 0; + } + + if ($code === null) { + $code = 0; + } + + $this->statusCode = $statusCode; + $this->headers = $headers; + $this->errorCode = $code; + + parent::__construct($message, $statusCode, $previous); + } + + public function getStatusCode() + { + return $this->statusCode; + } + + public function getHeaders() + { + return $this->headers; + } + + public function getErrorCode() + { + return $this->errorCode; + } +} diff --git a/application/api/library/ExceptionHandle.php b/application/api/library/ExceptionHandle.php index 852f7ef..7c11118 100755 --- a/application/api/library/ExceptionHandle.php +++ b/application/api/library/ExceptionHandle.php @@ -13,6 +13,11 @@ class ExceptionHandle extends Handle public function render(Exception $e) { + // API 异常 + if ($e instanceof ApiException) { + return json(['code' => $e->getErrorCode(), 'msg' => $e->getMessage(), 'time' => time(), 'data' => null], $e->getStatusCode()); + } + // 在生产环境下返回code信息 if (!\think\Config::get('app_debug')) { $statuscode = $code = 500; diff --git a/application/api/validate/Worker.php b/application/api/validate/Worker.php new file mode 100644 index 0000000..496db24 --- /dev/null +++ b/application/api/validate/Worker.php @@ -0,0 +1,20 @@ + 'require|max:128', + ]; + + protected $message = [ + + ]; + + protected $scene = [ + 'phoneLogin' => ['code'], + ]; +} diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php index f685ca2..1ca0c4e 100755 --- a/application/common/controller/Api.php +++ b/application/common/controller/Api.php @@ -3,6 +3,7 @@ namespace app\common\controller; use app\common\library\Auth; +use app\services\BaseService; use think\Config; use think\exception\HttpResponseException; use think\exception\ValidateException; @@ -17,7 +18,7 @@ use think\Validate; /** * API控制器基类 */ -class Api +class Api extends BaseService { /** diff --git a/application/common/model/Worker.php b/application/common/model/Worker.php new file mode 100644 index 0000000..d6ebe9b --- /dev/null +++ b/application/common/model/Worker.php @@ -0,0 +1,18 @@ + 'https://api.fastadmin.net', ], + 'mini_program' => [ + 'app_id' => Env::get('mini_program.app_id', ''), + 'secret' => Env::get('mini_program.secret', ''), + ] ]; diff --git a/application/services/BaseService.php b/application/services/BaseService.php new file mode 100644 index 0000000..56e3b1f --- /dev/null +++ b/application/services/BaseService.php @@ -0,0 +1,39 @@ + config('mini_program.app_id'), + 'secret' => config('mini_program.secret'), + ]; + $app = Factory::miniProgram($config); + $phoneInfo = $app->getPhoneNumber($code); + + if (empty($phoneInfo)) { + $this->apiError('手机号登录失败', 0, $phoneInfo); + } + + if ($phoneInfo['errcode'] !== 0) { + $this->apiError('手机号登录失败', 0, $phoneInfo); + } + + $phone = $phoneInfo['phone_info']['phoneNumber']; + dump($phone); + } +} From 49d7b3f1acdd3d94cb623037529463953e8d67b6 Mon Sep 17 00:00:00 2001 From: gcd Date: Fri, 28 Mar 2025 10:01:30 +0800 Subject: [PATCH 04/35] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Worker.php | 19 ++++++++--- application/api/validate/Worker.php | 5 +-- application/services/BaseService.php | 9 +++-- application/services/WorkerService.php | 46 ++++++++++++++++++++------ 4 files changed, 61 insertions(+), 18 deletions(-) diff --git a/application/api/controller/Worker.php b/application/api/controller/Worker.php index 70aa643..5417afa 100644 --- a/application/api/controller/Worker.php +++ b/application/api/controller/Worker.php @@ -6,17 +6,28 @@ use app\common\controller\Api; class Worker extends Api { - protected $noNeedLogin = ['phoneLogin']; + protected $noNeedLogin = ['login']; protected $noNeedRight = ['*']; - function phoneLogin() + function login() { $params = $this->request->request(); - $validate = $this->validate($params, \app\api\validate\Worker::class . '.phoneLogin'); + $validate = $this->validate($params, \app\api\validate\Worker::class . '.login'); if ($validate !== true) { $this->error($validate); } - $this->success('登录成功', $this->getWorkerService()->phoneLogin($params['code'])); + $this->success('登录成功', $this->getWorkerService()->login($params['code'])); + } + + function bindPhoneNumber() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\api\validate\Worker::class . '.bindPhoneNumber'); + if ($validate !== true) { + $this->error($validate); + } + + $this->success('操作成功', $this->getWorkerService()->bindPhoneNumber($params['code'])); } } diff --git a/application/api/validate/Worker.php b/application/api/validate/Worker.php index 496db24..b27e3d5 100644 --- a/application/api/validate/Worker.php +++ b/application/api/validate/Worker.php @@ -7,7 +7,7 @@ use think\Validate; class Worker extends Validate { protected $rule = [ - 'code|手机号获取凭证 code ' => 'require|max:128', + 'code' => 'require|max:128', ]; protected $message = [ @@ -15,6 +15,7 @@ class Worker extends Validate ]; protected $scene = [ - 'phoneLogin' => ['code'], + 'login' => ['code'], + 'bindPhoneNumber' => ['code'], ]; } diff --git a/application/services/BaseService.php b/application/services/BaseService.php index 56e3b1f..9cd0008 100644 --- a/application/services/BaseService.php +++ b/application/services/BaseService.php @@ -13,8 +13,13 @@ class BaseService protected function apiError($msg, $code = 0, $data = []) { if (!empty($data)) { - array_unshift($data, $msg); - Log::log($data); + array_unshift($data, ['msg' => $msg]); + + $log = [ + '请求参数' => $_REQUEST, + '结果' => $data, + ]; + Log::log($log); } throw new ApiException($msg, $code); diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index 8ad697e..fb2b075 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -2,29 +2,55 @@ namespace app\services; -use app\api\library\ApiException; use EasyWeChat\Factory; +use EasyWeChat\Kernel\Exceptions\InvalidConfigException; +use EasyWeChat\MiniProgram\Application; class WorkerService extends BaseService { - public function phoneLogin(string $code) + public function bindPhoneNumber(string $code) { - $config = [ - 'app_id' => config('mini_program.app_id'), - 'secret' => config('mini_program.secret'), - ]; - $app = Factory::miniProgram($config); - $phoneInfo = $app->getPhoneNumber($code); + //getPhoneNumber 方法通过魔术方法 __call 获取 + $phoneInfo = $this->getMiniProgramApp()->getPhoneNumber($code); if (empty($phoneInfo)) { - $this->apiError('手机号登录失败', 0, $phoneInfo); + $this->apiError('获取手机号失败', 0, $phoneInfo); } if ($phoneInfo['errcode'] !== 0) { - $this->apiError('手机号登录失败', 0, $phoneInfo); + $this->apiError('获取手机号失败', 0, $phoneInfo); } $phone = $phoneInfo['phone_info']['phoneNumber']; dump($phone); } + + public function login(string $code) + { + $app = $this->getMiniProgramApp(); + try { + $info = $app->auth->session($code); + } catch (InvalidConfigException $e) { + $this->apiError('登录失败', $e); + } + + if (isset($info['errcode']) && $info['errcode'] !== 0) { + $this->apiError('登录失败', 0, $info); + } + + dd($info); + } + + /** + * 获取小程序 App + * @return Application + */ + private function getMiniProgramApp(): Application + { + $config = [ + 'app_id' => config('mini_program.app_id'), + 'secret' => config('mini_program.secret'), + ]; + return Factory::miniProgram($config); + } } From a36157d40642c9a9474ecab7e158a8f34e5ecb9f Mon Sep 17 00:00:00 2001 From: gcd Date: Fri, 28 Mar 2025 12:46:53 +0800 Subject: [PATCH 05/35] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Worker.php | 33 -- application/common/controller/WorkerApi.php | 310 ++++++++++++++++++ application/common/model/WorkerVendor.php | 18 + application/services/BaseService.php | 27 ++ application/services/WorkerService.php | 62 ++-- application/services/WorkerVendorService.php | 33 ++ application/worker/config.php | 6 + application/worker/controller/Worker.php | 39 +++ .../worker/controller/WorkerVendor.php | 10 + .../{api => worker}/validate/Worker.php | 7 +- 10 files changed, 490 insertions(+), 55 deletions(-) delete mode 100644 application/api/controller/Worker.php create mode 100644 application/common/controller/WorkerApi.php create mode 100644 application/common/model/WorkerVendor.php create mode 100644 application/services/WorkerVendorService.php create mode 100644 application/worker/config.php create mode 100644 application/worker/controller/Worker.php create mode 100644 application/worker/controller/WorkerVendor.php rename application/{api => worker}/validate/Worker.php (54%) diff --git a/application/api/controller/Worker.php b/application/api/controller/Worker.php deleted file mode 100644 index 5417afa..0000000 --- a/application/api/controller/Worker.php +++ /dev/null @@ -1,33 +0,0 @@ -request->request(); - $validate = $this->validate($params, \app\api\validate\Worker::class . '.login'); - if ($validate !== true) { - $this->error($validate); - } - - $this->success('登录成功', $this->getWorkerService()->login($params['code'])); - } - - function bindPhoneNumber() - { - $params = $this->request->request(); - $validate = $this->validate($params, \app\api\validate\Worker::class . '.bindPhoneNumber'); - if ($validate !== true) { - $this->error($validate); - } - - $this->success('操作成功', $this->getWorkerService()->bindPhoneNumber($params['code'])); - } -} diff --git a/application/common/controller/WorkerApi.php b/application/common/controller/WorkerApi.php new file mode 100644 index 0000000..da77245 --- /dev/null +++ b/application/common/controller/WorkerApi.php @@ -0,0 +1,310 @@ +request = is_null($request) ? Request::instance() : $request; + + // 控制器初始化 + $this->_initialize(); + } + + /** + * 初始化操作 + * @access protected + */ + protected function _initialize() + { + //跨域请求检测 + check_cors_request(); + + // 检测IP是否允许 + check_ip_allowed(); + + //移除HTML标签 + $this->request->filter('trim,strip_tags,htmlspecialchars'); + + // token + $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token'))); + if (!$this->match($this->noNeedLogin)) { + $this->init($token); + } else { + if ($token) { + $this->init($token); + } + } + + return true; + } + + /** + * 检测当前控制器和方法是否匹配传递的数组 + * + * @param array $arr 需要验证权限的数组 + * @return boolean + */ + public function match($arr = []) + { + $request = Request::instance(); + $arr = is_array($arr) ? $arr : explode(',', $arr); + if (!$arr) { + return false; + } + $arr = array_map('strtolower', $arr); + // 是否存在 + if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) { + return true; + } + + // 没找到匹配 + return false; + } + + /** + * 操作成功返回的数据 + * @param string $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为1 + * @param string $type 输出类型 + * @param array $header 发送的 Header 信息 + */ + protected function success($msg = '', $data = null, $code = 1, $type = null, array $header = []) + { + $this->result($msg, $data, $code, $type, $header); + } + + /** + * 操作失败返回的数据 + * @param string $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为0 + * @param string $type 输出类型 + * @param array $header 发送的 Header 信息 + */ + protected function error($msg = '', $data = null, $code = 0, $type = null, array $header = []) + { + $this->result($msg, $data, $code, $type, $header); + } + + /** + * 返回封装后的 API 数据到客户端 + * @access protected + * @param mixed $msg 提示信息 + * @param mixed $data 要返回的数据 + * @param int $code 错误码,默认为0 + * @param string $type 输出类型,支持json/xml/jsonp + * @param array $header 发送的 Header 信息 + * @return void + * @throws HttpResponseException + */ + protected function result($msg, $data = null, $code = 0, $type = null, array $header = []) + { + $result = [ + 'code' => $code, + 'msg' => $msg, + 'time' => Request::instance()->server('REQUEST_TIME'), + 'data' => $data, + ]; + // 如果未设置类型则自动判断 + $type = $type ? $type : ($this->request->param(config('var_jsonp_handler')) ? 'jsonp' : $this->responseType); + + if (isset($header['statuscode'])) { + $code = $header['statuscode']; + unset($header['statuscode']); + } else { + //未设置状态码,根据code值判断 + $code = $code >= 1000 || $code < 200 ? 200 : $code; + } + $response = Response::create($result, $type, $code)->header($header); + throw new HttpResponseException($response); + } + + /** + * 师傅登录 + * @param int $id + * @return bool + */ + public function workerLogin(int $id): bool + { + $user = $this->getWorkerModel()->find($id); + $this->tryLogin($user); + + $user = $user->toArray(); + $user['token'] = $this->getTokenByUserId($user['id']); + + $this->user = $user; + + return true; + } + + /** + * 验证数据 + * @access protected + * @param array $data 数据 + * @param string|array $validate 验证器名或者验证规则数组 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 + * @param mixed $callback 回调方法(闭包) + * @return array|string|true + * @throws ValidateException + */ + public function validate($data, $validate, $messageHeader = '', $message = [], $batch = false, $callback = null) + { + if (is_array($validate)) { + $v = Loader::validate(); + $v->rule($validate); + } else { + // 支持场景 + if (strpos($validate, '.')) { + list($validate, $scene) = explode('.', $validate); + } + $v = Loader::validate($validate); + + !empty($scene) && $v->scene($scene); + } + + // 批量验证 + if ($batch || $this->batchValidate) { + $v->batch(true); + } + // 设置错误信息 + if (is_array($message)) { + $v->message($message); + } + // 使用回调验证 + if ($callback && is_callable($callback)) { + call_user_func_array($callback, [$v, &$data]); + } + + if (!$v->check($data)) { + $errorMessage = $v->getError(); + if ($messageHeader) { + $errorMessage = "$messageHeader$errorMessage"; + } + + if ($this->failException) { + throw new ValidateException($errorMessage); + } + + throw new ApiException($errorMessage); + } + + return true; + } + + private function init($token) + { + if ($this->user) { + return true; + } + + $data = Token::get($token); + if (!$data) { + throw new ApiException('登录已失效', 401); + } + + $this->token = $token; + + $user = $this->getWorkerModel() + ->field($this->allowFields) + ->where('id', $data['user_id']) + ->find(); + + $this->tryLogin($user); + + $this->user = $user->toArray(); + + return true; + } + + private function tryLogin($user) + { + if (!$user) { + throw new ApiException('用户不存在,请联系平台'); + } + + if ($user->status === 0) { + throw new ApiException('当前账号不可用'); + } + + return true; + } + + protected function getTokenByUserId($userId) + { + $token = Random::uuid(); + Token::set($token, $userId, $this->keeptime); + + return $token; + } +} diff --git a/application/common/model/WorkerVendor.php b/application/common/model/WorkerVendor.php new file mode 100644 index 0000000..9c01940 --- /dev/null +++ b/application/common/model/WorkerVendor.php @@ -0,0 +1,18 @@ +getMiniProgramApp()->getPhoneNumber($code); +// $phoneInfo = $this->getMiniProgramApp()->getPhoneNumber($code); +// +// if (empty($phoneInfo)) { +// $this->apiError('获取手机号失败', 0, $phoneInfo); +// } +// +// if ($phoneInfo['errcode'] !== 0) { +// $this->apiError('获取手机号失败', 0, $phoneInfo); +// } +// +// $phone = $phoneInfo['phone_info']['phoneNumber']; - if (empty($phoneInfo)) { - $this->apiError('获取手机号失败', 0, $phoneInfo); + $phone = '18628195903'; + $tokenData = Token::get($vendorToken); + if (!$tokenData) { + $this->apiError('vendor_token 无效'); } - if ($phoneInfo['errcode'] !== 0) { - $this->apiError('获取手机号失败', 0, $phoneInfo); - } - - $phone = $phoneInfo['phone_info']['phoneNumber']; + $workerVendorId = $tokenData['user_id']; dump($phone); } public function login(string $code) { - $app = $this->getMiniProgramApp(); - try { - $info = $app->auth->session($code); - } catch (InvalidConfigException $e) { - $this->apiError('登录失败', $e); +// $app = $this->getMiniProgramApp(); +// try { +// $info = $app->auth->session($code); +// } catch (InvalidConfigException $e) { +// $this->apiError('登录失败', $e); +// } +// +// if (isset($info['errcode']) && $info['errcode'] !== 0) { +// $this->apiError('登录失败', 0, $info); +// } + + $info['openid'] = 'oNgcn42DRwoG_qE6jjvsCSbM4cX8'; + $workerVendor = $this->getWorkerVendorService()->getVendorByOpenid($info['openid']); + + //创建 + if (empty($workerVendor)) { + try { + $this->getWorkerVendorService()->createWechatMpVendor($info['openid']); + } catch (\Exception $e) { + $this->apiError('登录失败', $e, $info); + } + + $workerVendor = $this->getWorkerVendorService()->getVendorByOpenid($info['openid']); } - if (isset($info['errcode']) && $info['errcode'] !== 0) { - $this->apiError('登录失败', 0, $info); - } - - dd($info); + return $workerVendor->toArray(); } /** diff --git a/application/services/WorkerVendorService.php b/application/services/WorkerVendorService.php new file mode 100644 index 0000000..4a7f1ad --- /dev/null +++ b/application/services/WorkerVendorService.php @@ -0,0 +1,33 @@ +getWorkerVendorModel()->where(['openid' => $openid])->find(); + } + + /** + * 创建微信小程序账户 + * @param string $openid + */ + public function createWechatMpVendor(string $openid) + { + $vendor = $this->getWorkerVendorModel(); + $vendor->vendor = 'wechat'; + $vendor->platform = 'WechatMp'; + $vendor->unionid = ''; + $vendor->openid = $openid; + $vendor->worker_id = 0; + $vendor->create_time = datetime(time()); + $vendor->save(); + + return $vendor->id; + } +} diff --git a/application/worker/config.php b/application/worker/config.php new file mode 100644 index 0000000..0844157 --- /dev/null +++ b/application/worker/config.php @@ -0,0 +1,6 @@ + '\\app\\api\\library\\ExceptionHandle', +]; diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php new file mode 100644 index 0000000..9a9dd13 --- /dev/null +++ b/application/worker/controller/Worker.php @@ -0,0 +1,39 @@ +request->request(); + $validate = $this->validate($params, \app\worker\validate\Worker::class . '.login'); + if ($validate !== true) { + $this->error($validate); + } + + $workerVendor = $this->getWorkerService()->login($params['code']); + + //存在师傅id,直接登录 + if ($workerVendor['worker_id']) { + $this->workerLogin($workerVendor['worker_id']); + $this->success('登录成功', $this->user); + } + + $this->error('请绑定手机号', ['vendor_token' => $this->getTokenByUserId($workerVendor['id'])]); + } + + function bindPhoneNumber() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\Worker::class . '.bindPhoneNumber'); + if ($validate !== true) { + $this->error($validate); + } + + $this->success('操作成功', $this->getWorkerService()->bindPhoneNumber($params['code'], $params['vendor_token'])); + } +} diff --git a/application/worker/controller/WorkerVendor.php b/application/worker/controller/WorkerVendor.php new file mode 100644 index 0000000..806a0cb --- /dev/null +++ b/application/worker/controller/WorkerVendor.php @@ -0,0 +1,10 @@ + 'require|max:128', + 'vendor_token' => 'require|max:128', ]; protected $message = [ @@ -15,7 +16,7 @@ class Worker extends Validate ]; protected $scene = [ - 'login' => ['code'], - 'bindPhoneNumber' => ['code'], + 'login' => ['code'], + 'bindPhoneNumber' => ['code', 'vendor_token'], ]; } From aa5f46bdd39d239bea444174d6695ff9bf83987d Mon Sep 17 00:00:00 2001 From: gcd Date: Sat, 29 Mar 2025 09:22:16 +0800 Subject: [PATCH 06/35] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E3=80=81=E7=BB=91=E5=AE=9A=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Worker.php | 1 - application/config.php | 2 +- application/services/WorkerService.php | 95 ++++++++++++++------ application/services/WorkerVendorService.php | 5 ++ application/worker/controller/Worker.php | 10 ++- 5 files changed, 81 insertions(+), 32 deletions(-) diff --git a/application/common/model/Worker.php b/application/common/model/Worker.php index d6ebe9b..fad9738 100644 --- a/application/common/model/Worker.php +++ b/application/common/model/Worker.php @@ -14,5 +14,4 @@ class Worker extends Model ]; - } diff --git a/application/config.php b/application/config.php index 49a2749..44e6b12 100755 --- a/application/config.php +++ b/application/config.php @@ -312,7 +312,7 @@ return [ //插件纯净模式,插件启用后是否删除插件目录的application、public和assets文件夹 'addon_pure_mode' => true, //允许跨域的域名,多个以,分隔 - 'cors_request_domain' => 'localhost,127.0.0.1,chrome-extension://gahjcfmabepcnfmfanjhcobdaalgpjoh', + 'cors_request_domain' => 'localhost,127.0.0.1,*', //版本号 'version' => '1.5.3.20250217', //API接口地址 diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index ee25a91..6d0fb72 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -2,7 +2,6 @@ namespace app\services; -use app\api\library\ApiException; use app\common\library\Token; use EasyWeChat\Factory; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; @@ -12,43 +11,41 @@ class WorkerService extends BaseService { public function bindPhoneNumber(string $code, string $vendorToken) { - //getPhoneNumber 方法通过魔术方法 __call 获取 -// $phoneInfo = $this->getMiniProgramApp()->getPhoneNumber($code); -// -// if (empty($phoneInfo)) { -// $this->apiError('获取手机号失败', 0, $phoneInfo); -// } -// -// if ($phoneInfo['errcode'] !== 0) { -// $this->apiError('获取手机号失败', 0, $phoneInfo); -// } -// -// $phone = $phoneInfo['phone_info']['phoneNumber']; + $phone = $this->getPhoneNumber($code); + $worker = $this->getWorkerService()->getByTel($phone); + $this->tryBindPhoneNumber($worker); - $phone = '18628195903'; $tokenData = Token::get($vendorToken); if (!$tokenData) { $this->apiError('vendor_token 无效'); } - $workerVendorId = $tokenData['user_id']; - dump($phone); + $workerVendor = $this->getWorkerVendorModel()->find($tokenData['user_id']); + if ($workerVendor->worker_id) { + $this->apiError('绑定失败,该微信已绑定手机号'); + } + + //绑定手机号 + $workerVendor->worker_id = $worker->id; + $workerVendor->save(); + + Token::delete($vendorToken); + return $worker->id; } public function login(string $code) { -// $app = $this->getMiniProgramApp(); -// try { -// $info = $app->auth->session($code); -// } catch (InvalidConfigException $e) { -// $this->apiError('登录失败', $e); -// } -// -// if (isset($info['errcode']) && $info['errcode'] !== 0) { -// $this->apiError('登录失败', 0, $info); -// } + $app = $this->getMiniProgramApp(); + try { + $info = $app->auth->session($code); + } catch (InvalidConfigException $e) { + $this->apiError('登录失败', $e); + } + + if (isset($info['errcode']) && $info['errcode'] !== 0) { + $this->apiError('登录失败', 0, $info); + } - $info['openid'] = 'oNgcn42DRwoG_qE6jjvsCSbM4cX8'; $workerVendor = $this->getWorkerVendorService()->getVendorByOpenid($info['openid']); //创建 @@ -77,4 +74,48 @@ class WorkerService extends BaseService ]; return Factory::miniProgram($config); } + + public function getPhoneNumber(string $code) + { + //getPhoneNumber 方法通过魔术方法 __call 获取 + $phoneInfo = $this->getMiniProgramApp()->getPhoneNumber($code); + + if (empty($phoneInfo)) { + $this->apiError('获取手机号失败', 0, $phoneInfo); + } + + if ($phoneInfo['errcode'] !== 0) { + $this->apiError('获取手机号失败', 0, $phoneInfo); + } + + return $phoneInfo['phone_info']['phoneNumber']; + } + + private function getByTel(string $phone) + { + return $this->getWorkerModel()->where('tel', $phone)->find(); + } + + /** + * 尝试绑定手机号 + * @param $worker + * @return true + */ + private function tryBindPhoneNumber($worker) + { + if (empty($worker)) { + $this->apiError('绑定失败,该手机号未注册'); + } + + if ($worker->status === 0) { + $this->apiError('绑定失败,您的账号不可用'); + } + + $workerVendor = $this->getWorkerVendorService()->getByWorkerIdAndPlatform($worker->id, 'WechatMp'); + if ($workerVendor) { + $this->apiError('绑定失败,当前手机号已被其他微信绑定'); + } + + return true; + } } diff --git a/application/services/WorkerVendorService.php b/application/services/WorkerVendorService.php index 4a7f1ad..bfaf513 100644 --- a/application/services/WorkerVendorService.php +++ b/application/services/WorkerVendorService.php @@ -30,4 +30,9 @@ class WorkerVendorService extends BaseService return $vendor->id; } + + public function getByWorkerIdAndPlatform(int $workerId, string $platform) + { + return $this->getWorkerVendorModel()->where(['worker_id' => $workerId, 'platform' => $platform])->find(); + } } diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index 9a9dd13..737545c 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -1,4 +1,5 @@ request->request(); $validate = $this->validate($params, \app\worker\validate\Worker::class . '.login'); @@ -26,7 +27,7 @@ class Worker extends WorkerApi $this->error('请绑定手机号', ['vendor_token' => $this->getTokenByUserId($workerVendor['id'])]); } - function bindPhoneNumber() + public function bindPhoneNumber() { $params = $this->request->request(); $validate = $this->validate($params, \app\worker\validate\Worker::class . '.bindPhoneNumber'); @@ -34,6 +35,9 @@ class Worker extends WorkerApi $this->error($validate); } - $this->success('操作成功', $this->getWorkerService()->bindPhoneNumber($params['code'], $params['vendor_token'])); + $workerId = $this->getWorkerService()->bindPhoneNumber($params['code'], $params['vendor_token']); + $this->workerLogin($workerId); + + $this->success('绑定成功', $this->user); } } From 578e38b99acd8d1c2509bcef967bbbe9cf6c3026 Mon Sep 17 00:00:00 2001 From: gcd Date: Sat, 29 Mar 2025 11:45:26 +0800 Subject: [PATCH 07/35] =?UTF-8?q?=E6=B8=B8=E5=AE=A2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/worker/controller/Worker.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index 737545c..feab2f5 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -6,7 +6,7 @@ use app\common\controller\WorkerApi; class Worker extends WorkerApi { - protected $noNeedLogin = ['login', 'bindPhoneNumber']; + protected $noNeedLogin = ['login', 'bindPhoneNumber', 'guestLogin']; public function login() { @@ -40,4 +40,10 @@ class Worker extends WorkerApi $this->success('绑定成功', $this->user); } + + public function guestLogin() + { + $this->workerLogin(1); + $this->success('登录成功', $this->user); + } } From 9859f0667226aae7191279efb7c0fc7dff1bbf06 Mon Sep 17 00:00:00 2001 From: gcd Date: Sat, 29 Mar 2025 14:19:40 +0800 Subject: [PATCH 08/35] =?UTF-8?q?feat:=20=E9=80=80=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/controller/WorkerApi.php | 9 +++++++++ application/worker/controller/Worker.php | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/application/common/controller/WorkerApi.php b/application/common/controller/WorkerApi.php index da77245..939f90f 100644 --- a/application/common/controller/WorkerApi.php +++ b/application/common/controller/WorkerApi.php @@ -207,6 +207,15 @@ class WorkerApi extends BaseService return true; } + public function workerLogout(): bool + { + if ($this->token) { + Token::delete($this->token); + } + + return true; + } + /** * 验证数据 * @access protected diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index feab2f5..c112d64 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -46,4 +46,10 @@ class Worker extends WorkerApi $this->workerLogin(1); $this->success('登录成功', $this->user); } + + public function logout() + { + $this->workerLogout(); + $this->success('操作成功'); + } } From fd4eecbf9909395865a07ed7e2188ba06aadb3c3 Mon Sep 17 00:00:00 2001 From: gcd Date: Sat, 29 Mar 2025 15:10:38 +0800 Subject: [PATCH 09/35] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/worker/controller/Worker.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index c112d64..b6fd77f 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -52,4 +52,9 @@ class Worker extends WorkerApi $this->workerLogout(); $this->success('操作成功'); } + + public function show() + { + $this->success('操作成功', $this->user); + } } From 191156ec9601988a62fe436edff968e0adf8f48a Mon Sep 17 00:00:00 2001 From: gcd Date: Sun, 30 Mar 2025 10:23:25 +0800 Subject: [PATCH 10/35] =?UTF-8?q?feat:=20=E8=AE=A2=E5=8D=95=E6=B4=BE?= =?UTF-8?q?=E5=8D=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/OrderDispatch.php | 21 +++++++++++++++++++ application/services/BaseService.php | 17 +++++++++++++++ application/services/OrderDispatchService.php | 18 ++++++++++++++++ .../worker/controller/OrderDispatch.php | 16 ++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 application/common/model/OrderDispatch.php create mode 100644 application/services/OrderDispatchService.php create mode 100644 application/worker/controller/OrderDispatch.php diff --git a/application/common/model/OrderDispatch.php b/application/common/model/OrderDispatch.php new file mode 100644 index 0000000..9d50ef7 --- /dev/null +++ b/application/common/model/OrderDispatch.php @@ -0,0 +1,21 @@ +belongsTo('User','uid'); +// } +} diff --git a/application/services/BaseService.php b/application/services/BaseService.php index 971f1c2..7d8b3ab 100644 --- a/application/services/BaseService.php +++ b/application/services/BaseService.php @@ -8,6 +8,7 @@ use app\common\model\Worker; use think\Log; use app\common\model\WorkerVendor; +use app\common\model\OrderDispatch; //{%add use model%} class BaseService @@ -67,5 +68,21 @@ class BaseService return app(WorkerVendor::class, true); } + /** + * @return OrderDispatchService + */ + protected function getOrderDispatchService() + { + return app(OrderDispatchService::class); + } + + /** + * @return OrderDispatch + */ + protected function getOrderDispatchModel() + { + return app(OrderDispatch::class, true); + } + //{%add function code%} } diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php new file mode 100644 index 0000000..41e99ed --- /dev/null +++ b/application/services/OrderDispatchService.php @@ -0,0 +1,18 @@ +getOrderDispatchModel() + ->where('status', OrderDispatch::STATUS_TOGET) + ->where('worker_id', $workerId) + ->field(['id', 'order_id', 'status', 'remark', 'plan_time', 'create_time']) + ->paginate($pageSize); + return $model; + } +} diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php new file mode 100644 index 0000000..6ddf3d8 --- /dev/null +++ b/application/worker/controller/OrderDispatch.php @@ -0,0 +1,16 @@ +getOrderDispatchService()->dispatchList($this->user['id'], $this->request->request('page_size', 20)); + $this->success('获取成功', $res); + } +} From a8d2980e2399050c96eb2a343e60c1b5e7ebaa68 Mon Sep 17 00:00:00 2001 From: gcd Date: Sun, 30 Mar 2025 10:24:35 +0800 Subject: [PATCH 11/35] =?UTF-8?q?feat:=20=E8=AE=A2=E5=8D=95=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Order.php | 18 ++++++++++++++++++ application/services/BaseService.php | 17 +++++++++++++++++ application/services/OrderService.php | 8 ++++++++ application/worker/controller/Order.php | 10 ++++++++++ 4 files changed, 53 insertions(+) create mode 100644 application/common/model/Order.php create mode 100644 application/services/OrderService.php create mode 100644 application/worker/controller/Order.php diff --git a/application/common/model/Order.php b/application/common/model/Order.php new file mode 100644 index 0000000..278eb6f --- /dev/null +++ b/application/common/model/Order.php @@ -0,0 +1,18 @@ + Date: Mon, 31 Mar 2025 12:02:38 +0800 Subject: [PATCH 12/35] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8D=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/OrderDispatch.php | 8 ++++---- application/services/OrderDispatchService.php | 9 ++++++--- application/worker/controller/Order.php | 2 +- application/worker/controller/Worker.php | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/application/common/model/OrderDispatch.php b/application/common/model/OrderDispatch.php index 9d50ef7..362f9eb 100644 --- a/application/common/model/OrderDispatch.php +++ b/application/common/model/OrderDispatch.php @@ -14,8 +14,8 @@ class OrderDispatch extends Model ]; -// public function orderInfo() -// { -// return $this->belongsTo('User','uid'); -// } + public function orderInfo() + { + return $this->belongsTo(Order::class,'order_id', 'id'); + } } diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 41e99ed..009e93d 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -8,11 +8,14 @@ class OrderDispatchService extends BaseService { public function dispatchList(int $workerId, int $pageSize) { - $model = $this->getOrderDispatchModel() + return $this->getOrderDispatchModel() + ->with(['orderInfo' => function ($query) { + $query->field('id,order_no,item_id,item_title,receive_type,address,lng,lat,plan_time,online_amount,discount_amount'); + }]) ->where('status', OrderDispatch::STATUS_TOGET) ->where('worker_id', $workerId) - ->field(['id', 'order_id', 'status', 'remark', 'plan_time', 'create_time']) + ->field(['id', 'order_id', 'status', 'remark', 'create_time']) + ->order('id desc') ->paginate($pageSize); - return $model; } } diff --git a/application/worker/controller/Order.php b/application/worker/controller/Order.php index 121d85d..3976d33 100644 --- a/application/worker/controller/Order.php +++ b/application/worker/controller/Order.php @@ -6,5 +6,5 @@ use app\common\controller\WorkerApi; class Order extends WorkerApi { - protected $noNeedLogin = ['*']; + protected $noNeedLogin = []; } diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index b6fd77f..2ec18dd 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -43,7 +43,7 @@ class Worker extends WorkerApi public function guestLogin() { - $this->workerLogin(1); + $this->workerLogin(9); $this->success('登录成功', $this->user); } From 7ace9cc65c60b2b9a19ceb9b3fdb94285487bfae Mon Sep 17 00:00:00 2001 From: gcd Date: Tue, 1 Apr 2025 16:29:11 +0800 Subject: [PATCH 13/35] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Order.php | 5 ++++- application/services/OrderDispatchService.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/application/common/model/Order.php b/application/common/model/Order.php index 278eb6f..2c60e3b 100644 --- a/application/common/model/Order.php +++ b/application/common/model/Order.php @@ -14,5 +14,8 @@ class Order extends Model ]; - + public function area() + { + return $this->belongsTo(\app\admin\model\Area::class,'area_id', 'area_code'); + } } diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 009e93d..9abfbed 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -10,7 +10,9 @@ class OrderDispatchService extends BaseService { return $this->getOrderDispatchModel() ->with(['orderInfo' => function ($query) { - $query->field('id,order_no,item_id,item_title,receive_type,address,lng,lat,plan_time,online_amount,discount_amount'); + $query->with(['area' => function ($query) { + $query->field('id,area_code,merge_name'); + }])->field('id,order_no,item_id,item_title,receive_type,address,lng,lat,plan_time,online_amount,discount_amount,area_id'); }]) ->where('status', OrderDispatch::STATUS_TOGET) ->where('worker_id', $workerId) From 11ec750e494c12fc38f3154d8c1c09c72101ac90 Mon Sep 17 00:00:00 2001 From: gcd Date: Tue, 1 Apr 2025 20:56:11 +0800 Subject: [PATCH 14/35] =?UTF-8?q?=E5=B8=88=E5=82=85=E6=8E=A5=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 82 +++++++++++++++++++ application/services/OrderService.php | 3 +- application/services/WorkerService.php | 19 +++++ application/services/WorkerVendorService.php | 5 ++ .../worker/controller/OrderDispatch.php | 20 +++++ application/worker/controller/Worker.php | 20 +++++ application/worker/validate/OrderDispatch.php | 21 +++++ 7 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 application/worker/validate/OrderDispatch.php diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 9abfbed..97ecc43 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -2,7 +2,11 @@ namespace app\services; +use app\admin\model\Order; use app\admin\model\OrderDispatch; +use app\api\library\ApiException; +use think\Db; +use think\Hook; class OrderDispatchService extends BaseService { @@ -20,4 +24,82 @@ class OrderDispatchService extends BaseService ->order('id desc') ->paginate($pageSize); } + + /** + * 师傅接单/拒接 + * @param int $workerId 师傅id + * @param int $orderDispatchId 派单id + * @param string $type 类型:accept=接单,reject=拒接 + * @return true + */ + public function orderConfirm(int $workerId, int $orderDispatchId, string $type) + { + $orderDispatch = $this->getOrderDispatchModel() + ->where('worker_id', $workerId) + ->where('id', $orderDispatchId) + ->find(); + if (!$orderDispatch) { + $this->apiError('订单不存在'); + } + + if ($orderDispatch->status !== OrderDispatch::STATUS_TOGET) { + $this->apiError('该订单已被接单'); + } + + //接单或拒接 + $orderDispatchStatus = $type == 'accept' ? OrderDispatch::STATUS_GOTIT : OrderDispatch::STATUS_REFUSED; + + Db::startTrans(); + try { + //接单 + $orderDispatch->status = $orderDispatchStatus; + $orderDispatch->save(); + + $orderDispatchChangeParams = [ + 'dispatch' => $orderDispatch, + 'remark' => $type == 'accept' ? '师傅接单' : '师傅拒接', + ]; + Hook::listen('order_dispatch_change', $orderDispatchChangeParams); + + //拒接,更新订单状态 + if ($type == 'reject') { + $order = $this->getOrderModel()->find($orderDispatch->order_id); + $order->status = Order::STATUS_DISPATCHING; + $order->save(); + + $orderChangeParams['order'] = $order; + $orderChangeParams['role'] = 2; + $orderChangeParams['auth'] = $this->getWorkerModel()->find($orderDispatch->worker_id); + $orderChangeParams['remark'] = '任务被师傅拒接[OrderDispatchId:' . $orderDispatch->id . '],订单状态回退'; + Hook::listen('order_change', $orderChangeParams); + } + + Db::commit(); + } catch (ApiException $e) { + Db::rollback(); + $this->apiError($e->getMessage()); + } catch (\Exception $e) { + Db::rollback(); + $this->apiError('操作失败', $e, [ + 'msg' => '师傅接单或拒接操作失败', + 'workerId' => $workerId, + 'orderDispatchId' => $orderDispatchId, + 'type' => $type, + ]); + } + + return true; + } } + + + + + + + + + + + + diff --git a/application/services/OrderService.php b/application/services/OrderService.php index 4d65a94..03b52cb 100644 --- a/application/services/OrderService.php +++ b/application/services/OrderService.php @@ -2,7 +2,8 @@ namespace app\services; +use app\admin\model\Order; + class OrderService extends BaseService { - } diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index 6d0fb72..a98feb5 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -9,6 +9,11 @@ use EasyWeChat\MiniProgram\Application; class WorkerService extends BaseService { + /** + * 绑定手机号 + * @param string $code + * @param string $vendorToken + */ public function bindPhoneNumber(string $code, string $vendorToken) { $phone = $this->getPhoneNumber($code); @@ -33,6 +38,11 @@ class WorkerService extends BaseService return $worker->id; } + /** + * 微信登录 + * @param string $code + * @return array + */ public function login(string $code) { $app = $this->getMiniProgramApp(); @@ -75,6 +85,11 @@ class WorkerService extends BaseService return Factory::miniProgram($config); } + /** + * 解密微信手机号 + * @param string $code + * @return mixed + */ public function getPhoneNumber(string $code) { //getPhoneNumber 方法通过魔术方法 __call 获取 @@ -91,6 +106,10 @@ class WorkerService extends BaseService return $phoneInfo['phone_info']['phoneNumber']; } + /** + * 通过手机号查询师傅信息 + * @param string $phone + */ private function getByTel(string $phone) { return $this->getWorkerModel()->where('tel', $phone)->find(); diff --git a/application/services/WorkerVendorService.php b/application/services/WorkerVendorService.php index bfaf513..602f88d 100644 --- a/application/services/WorkerVendorService.php +++ b/application/services/WorkerVendorService.php @@ -31,6 +31,11 @@ class WorkerVendorService extends BaseService return $vendor->id; } + /** + * 通过师傅id和平台查询师傅账号表信息 + * @param int $workerId + * @param string $platform + */ public function getByWorkerIdAndPlatform(int $workerId, string $platform) { return $this->getWorkerVendorModel()->where(['worker_id' => $workerId, 'platform' => $platform])->find(); diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index 6ddf3d8..e044ae3 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -8,9 +8,29 @@ class OrderDispatch extends WorkerApi { protected $noNeedLogin = []; + /** + * 待接单列表 + * @return void + */ public function index() { $res = $this->getOrderDispatchService()->dispatchList($this->user['id'], $this->request->request('page_size', 20)); $this->success('获取成功', $res); } + + /** + * 接单/拒接 + * @return void + */ + public function orderConfirm() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.orderConfirm'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderDispatchService()->orderConfirm($this->user['id'], $params['order_dispatch_id'], $params['type']); + $this->success('操作成功', $res); + } } diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index 2ec18dd..38eecc0 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -8,6 +8,10 @@ class Worker extends WorkerApi { protected $noNeedLogin = ['login', 'bindPhoneNumber', 'guestLogin']; + /** + * 微信登录 + * @return void + */ public function login() { $params = $this->request->request(); @@ -27,6 +31,10 @@ class Worker extends WorkerApi $this->error('请绑定手机号', ['vendor_token' => $this->getTokenByUserId($workerVendor['id'])]); } + /** + * 绑定手机号 + * @return void + */ public function bindPhoneNumber() { $params = $this->request->request(); @@ -41,18 +49,30 @@ class Worker extends WorkerApi $this->success('绑定成功', $this->user); } + /** + * 游客登录 + * @return void + */ public function guestLogin() { $this->workerLogin(9); $this->success('登录成功', $this->user); } + /** + * 退出登录 + * @return void + */ public function logout() { $this->workerLogout(); $this->success('操作成功'); } + /** + * 获取当前登录师傅信息 + * @return void + */ public function show() { $this->success('操作成功', $this->user); diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php new file mode 100644 index 0000000..981661c --- /dev/null +++ b/application/worker/validate/OrderDispatch.php @@ -0,0 +1,21 @@ + 'require|in:accept,reject', + 'order_dispatch_id|订单派单id' => 'require|number', + ]; + + protected $message = [ + + ]; + + protected $scene = [ + 'orderConfirm' => ['type', 'order_dispatch_id'], + ]; +} From e2031cb75b982c10d3a354ccb482a9f731ea5e95 Mon Sep 17 00:00:00 2001 From: gcd Date: Tue, 1 Apr 2025 22:48:14 +0800 Subject: [PATCH 15/35] =?UTF-8?q?feat:=20=E5=B7=A5=E4=BD=9C=E5=8F=B0?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 49 +++++++++++++++++++ .../worker/controller/OrderDispatch.php | 18 +++++++ application/worker/validate/OrderDispatch.php | 2 + 3 files changed, 69 insertions(+) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 97ecc43..082f179 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -25,6 +25,55 @@ class OrderDispatchService extends BaseService ->paginate($pageSize); } + /** + * @param int $workerId 师傅id + * @param string $type 类型:ongoing=进行中,today=当日,tomorrow=昨日,all=全部订单 + * @param int $pageSize + */ + public function workbenchOrderList(int $workerId, string $type, int $pageSize) + { + $model = $this->getOrderDispatchModel() + ->with(['orderInfo' => function ($query) { + $query->with(['area' => function ($query) { + $query->field('id,area_code,merge_name'); + }])->field('id,order_no,item_id,item_title,receive_type,address,lng,lat,plan_time,online_amount,discount_amount,area_id,customer,tel'); + }]) + ->where('worker_id', $workerId); + + $status = [ + OrderDispatch::STATUS_GOTIT, + OrderDispatch::STATUS_PLANIT, + OrderDispatch::STATUS_CLOCK, + ]; + switch ($type) { + case 'ongoing': + //所有已接单未完成的订单 + $model->whereIn('status', $status); + break; + case 'today': + $model->whereIn('status', $status); + $model->where('plan_time', '>=', date('Y-m-d 00:00:00')); + $model->where('plan_time', '<=', date('Y-m-d 23:59:59')); + break; + case 'tomorrow': + $model->whereIn('status', $status); + $model->where('plan_time', '>=', date('Y-m-d 00:00:00', strtotime('+1 day'))); + $model->where('plan_time', '<=', date('Y-m-d 23:59:59', strtotime('+1 day'))); + break; + case 'all': + $status[] = OrderDispatch::STATUS_FINISH; + $model->whereIn('status', $status); + break; + } + + $result = $model + ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'plan_time']) + ->order('id desc') + ->paginate($pageSize); + + return $result; + } + /** * 师傅接单/拒接 * @param int $workerId 师傅id diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index e044ae3..c8a39c4 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -18,6 +18,24 @@ class OrderDispatch extends WorkerApi $this->success('获取成功', $res); } + /** + * 工作台订单列表 + * @return void + */ + public function workbenchOrderList() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.workbenchOrderList'); + if ($validate !== true) { + $this->error($validate); + } + + $pageSize = $this->request->request('page_size', 20); + $type = $this->request->request('workbench_type'); + $res = $this->getOrderDispatchService()->workbenchOrderList($this->user['id'], $type, $pageSize); + $this->success('获取成功', $res); + } + /** * 接单/拒接 * @return void diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index 981661c..0f2efe1 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -9,6 +9,7 @@ class OrderDispatch extends Validate protected $rule = [ 'type|确认类型' => 'require|in:accept,reject', 'order_dispatch_id|订单派单id' => 'require|number', + 'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all', ]; protected $message = [ @@ -17,5 +18,6 @@ class OrderDispatch extends Validate protected $scene = [ 'orderConfirm' => ['type', 'order_dispatch_id'], + 'workbenchOrderList' => ['workbench_type'], ]; } From b06ae1a1ae8fbb024aadda92ada6ea9d7ca947ed Mon Sep 17 00:00:00 2001 From: gcd Date: Thu, 3 Apr 2025 17:26:53 +0800 Subject: [PATCH 16/35] =?UTF-8?q?feat:=20=E5=B7=A5=E4=BD=9C=E5=8F=B0?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 38 ++++++++++++++++--- .../worker/controller/OrderDispatch.php | 9 +++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 082f179..4374bdf 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -31,6 +31,37 @@ class OrderDispatchService extends BaseService * @param int $pageSize */ public function workbenchOrderList(int $workerId, string $type, int $pageSize) + { + $model = $this->getWorkbenchOrderModel($workerId, $type); + $result = $model + ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'plan_time']) + ->order('id desc') + ->paginate($pageSize); + + return $result; + } + + /** + * 统计工作台订单 + * @param int $workerId + * @return array + */ + public function countWorkbenchOrder(int $workerId) + { + return [ + 'ongoing' => $this->getWorkbenchOrderModel($workerId, 'ongoing')->count(), + 'today' => $this->getWorkbenchOrderModel($workerId, 'today')->count(), + 'tomorrow' => $this->getWorkbenchOrderModel($workerId, 'tomorrow')->count(), + 'all' => $this->getWorkbenchOrderModel($workerId, 'all')->count(), + ]; + } + + /** + * 获取工作台订单模型 + * @param int $workerId + * @param string $type + */ + private function getWorkbenchOrderModel(int $workerId, string $type) { $model = $this->getOrderDispatchModel() ->with(['orderInfo' => function ($query) { @@ -66,12 +97,7 @@ class OrderDispatchService extends BaseService break; } - $result = $model - ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'plan_time']) - ->order('id desc') - ->paginate($pageSize); - - return $result; + return $model; } /** diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index c8a39c4..aca2ede 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -36,6 +36,15 @@ class OrderDispatch extends WorkerApi $this->success('获取成功', $res); } + /** + * 统计工作台订单 + */ + public function countWorkbenchOrder() + { + $res = $this->getOrderDispatchService()->countWorkbenchOrder($this->user['id']); + $this->success('获取成功', $res); + } + /** * 接单/拒接 * @return void From 293b73724610ca2c3ed4da283b02ae31064ce22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sun, 13 Apr 2025 23:04:55 +0800 Subject: [PATCH 17/35] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=B4=BE?= =?UTF-8?q?=E5=8D=95=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 19 +++++++++++++++++++ .../worker/controller/OrderDispatch.php | 16 ++++++++++++++++ application/worker/validate/OrderDispatch.php | 1 + 3 files changed, 36 insertions(+) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 4374bdf..0ffe136 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -165,6 +165,25 @@ class OrderDispatchService extends BaseService return true; } + + public function dispatchInfo(int $workerId, int $orderDispatchId) + { + $res = $this->getOrderDispatchModel() + ->with(['orderInfo' => function ($query) { + $query->with(['area' => function ($query) { + $query->field('id,area_code,merge_name'); + }])->field('id,order_no,item_id,item_title,receive_type,address,lng,lat,plan_time,online_amount,discount_amount,area_id,customer,tel'); + }]) + ->where('id', $orderDispatchId) + ->where('worker_id', $workerId) + ->field(['id', 'order_id', 'status', 'remark', 'create_time']) + ->find(); + if (!$res) { + $this->apiError('订单不存在'); + } + + return $res; + } } diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index aca2ede..0a560c6 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -18,6 +18,22 @@ class OrderDispatch extends WorkerApi $this->success('获取成功', $res); } + /** + * 订单详情 + * @return void + */ + public function info() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.info'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderDispatchService()->dispatchInfo($this->user['id'], $this->request->request('order_dispatch_id')); + $this->success('获取成功', $res); + } + /** * 工作台订单列表 * @return void diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index 0f2efe1..c0b875a 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -19,5 +19,6 @@ class OrderDispatch extends Validate protected $scene = [ 'orderConfirm' => ['type', 'order_dispatch_id'], 'workbenchOrderList' => ['workbench_type'], + 'info' => ['order_dispatch_id'], ]; } From e986fc8dbdf1a2742c244a8d8ee9ac1f0ae2f5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Mon, 14 Apr 2025 10:06:27 +0800 Subject: [PATCH 18/35] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=B4=BE?= =?UTF-8?q?=E5=8D=95=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 0ffe136..a47ab42 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -176,7 +176,7 @@ class OrderDispatchService extends BaseService }]) ->where('id', $orderDispatchId) ->where('worker_id', $workerId) - ->field(['id', 'order_id', 'status', 'remark', 'create_time']) + ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'total', 'online_total', 'is_receipt']) ->find(); if (!$res) { $this->apiError('订单不存在'); From e25a2c29ea44e79d39f1e79cbb06cd78075075fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Mon, 14 Apr 2025 16:45:47 +0800 Subject: [PATCH 19/35] =?UTF-8?q?feat:=20=E9=A2=84=E7=BA=A6=E4=B8=8A?= =?UTF-8?q?=E9=97=A8=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 37 ++++++++++++++++++- .../worker/controller/OrderDispatch.php | 29 ++++++++++++++- application/worker/validate/OrderDispatch.php | 2 + 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index a47ab42..946ca2d 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -166,6 +166,11 @@ class OrderDispatchService extends BaseService return true; } + /** + * 派单详情 + * @param int $workerId 师傅id + * @param int $orderDispatchId 派单id + */ public function dispatchInfo(int $workerId, int $orderDispatchId) { $res = $this->getOrderDispatchModel() @@ -176,7 +181,7 @@ class OrderDispatchService extends BaseService }]) ->where('id', $orderDispatchId) ->where('worker_id', $workerId) - ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'total', 'online_total', 'is_receipt']) + ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'total', 'online_total', 'is_receipt', 'plan_time']) ->find(); if (!$res) { $this->apiError('订单不存在'); @@ -184,6 +189,36 @@ class OrderDispatchService extends BaseService return $res; } + + /** + * 提交预约上门时间 + * @param int $workerId 师傅id + * @param int $orderDispatchId 派单id + * @param string $planTime 预约时间 + * @return true + */ + public function appointmentTime(int $workerId, int $orderDispatchId, string $planTime) + { + $orderDispatch = $this->getOrderDispatchModel() + ->where('id', $orderDispatchId) + ->where('worker_id', $workerId) + ->find(); + if (!$orderDispatch) { + $this->apiError('订单不存在'); + } + + $orderDispatch->status = OrderDispatch::STATUS_PLANIT; + $orderDispatch->plan_time = $planTime; + $orderDispatch->save(); + + $orderDispatchChangeParams = [ + 'dispatch' => $orderDispatch, + 'remark' => '师傅已和客户预约,预约时间:' . $planTime, + ]; + Hook::listen('order_dispatch_change', $orderDispatchChangeParams); + + return true; + } } diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index 0a560c6..a4c036f 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -19,7 +19,7 @@ class OrderDispatch extends WorkerApi } /** - * 订单详情 + * 派单详情 * @return void */ public function info() @@ -76,4 +76,31 @@ class OrderDispatch extends WorkerApi $res = $this->getOrderDispatchService()->orderConfirm($this->user['id'], $params['order_dispatch_id'], $params['type']); $this->success('操作成功', $res); } + + /** + * 提交预约上门时间 + * @return void + */ + public function appointmentTime() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.appointmentTime'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderDispatchService()->appointmentTime($this->user['id'], $params['order_dispatch_id'], $params['plan_time']); + $this->success('操作成功', $res); + } } + + + + + + + + + + + diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index c0b875a..a89684c 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -10,6 +10,7 @@ class OrderDispatch extends Validate 'type|确认类型' => 'require|in:accept,reject', 'order_dispatch_id|订单派单id' => 'require|number', 'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all', + 'plan_time|预约时间' => 'require|date', ]; protected $message = [ @@ -20,5 +21,6 @@ class OrderDispatch extends Validate 'orderConfirm' => ['type', 'order_dispatch_id'], 'workbenchOrderList' => ['workbench_type'], 'info' => ['order_dispatch_id'], + 'appointmentTime' => ['order_dispatch_id', 'plan_time'], ]; } From 3cd36d1301d02540c687a00a157366426d6f2d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Wed, 16 Apr 2025 09:23:15 +0800 Subject: [PATCH 20/35] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=20OSS=20?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/worker/controller/Common.php | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 application/worker/controller/Common.php diff --git a/application/worker/controller/Common.php b/application/worker/controller/Common.php new file mode 100644 index 0000000..fc73c41 --- /dev/null +++ b/application/worker/controller/Common.php @@ -0,0 +1,25 @@ +request->post('name'); + if (empty($name)) { + $this->error('文件名必填'); + } + + $md5 = md5($name); + $auth = new \addons\alioss\library\Auth(); + $params = $auth->params($name, $md5); + $params['OSSAccessKeyId'] = $params['id']; + $params['success_action_status'] = 200; + $params['cdnurl'] = cdnurl('', true); + + $this->success('', null, $params); + } +} \ No newline at end of file From 3a2b25109bc42d97472d94c2332e7c09af000a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Thu, 17 Apr 2025 14:49:27 +0800 Subject: [PATCH 21/35] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=20OSS=20?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/extra/upload.php | 2 +- application/worker/controller/Common.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/extra/upload.php b/application/extra/upload.php index 24357af..ede454f 100755 --- a/application/extra/upload.php +++ b/application/extra/upload.php @@ -9,7 +9,7 @@ return [ /** * CDN地址 */ - 'cdnurl' => '', + 'cdnurl' => get_addon_config('alioss')['cdnurl'], /** * 文件保存格式 */ diff --git a/application/worker/controller/Common.php b/application/worker/controller/Common.php index fc73c41..1ffdfd5 100644 --- a/application/worker/controller/Common.php +++ b/application/worker/controller/Common.php @@ -20,6 +20,6 @@ class Common extends WorkerApi $params['success_action_status'] = 200; $params['cdnurl'] = cdnurl('', true); - $this->success('', null, $params); + $this->success('获取成功', $params); } } \ No newline at end of file From 04dd0ac1061db64630edca2c97765f118bd98e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Thu, 17 Apr 2025 15:40:07 +0800 Subject: [PATCH 22/35] =?UTF-8?q?feat:=20=E6=8F=90=E4=BA=A4=E4=B8=8A?= =?UTF-8?q?=E9=97=A8=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/worker/controller/OrderDispatch.php | 16 ++++++++++++++++ application/worker/validate/OrderDispatch.php | 2 ++ 2 files changed, 18 insertions(+) diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index a4c036f..49e8016 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -92,6 +92,22 @@ class OrderDispatch extends WorkerApi $res = $this->getOrderDispatchService()->appointmentTime($this->user['id'], $params['order_dispatch_id'], $params['plan_time']); $this->success('操作成功', $res); } + + /** + * 提交上门信息 + * @return void + */ + public function arrivedOnSite() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.arrivedOnSite'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderDispatchService()->arrivedOnSite($this->user['id'], $params['order_dispatch_id'], $params['img']); + $this->success('操作成功', $res); + } } diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index a89684c..9b472c9 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -11,6 +11,7 @@ class OrderDispatch extends Validate 'order_dispatch_id|订单派单id' => 'require|number', 'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all', 'plan_time|预约时间' => 'require|date', + 'img|上门图片' => 'require|max:300', ]; protected $message = [ @@ -22,5 +23,6 @@ class OrderDispatch extends Validate 'workbenchOrderList' => ['workbench_type'], 'info' => ['order_dispatch_id'], 'appointmentTime' => ['order_dispatch_id', 'plan_time'], + 'arrivedOnSite' => ['order_dispatch_id', 'img'], ]; } From cfb91dc2aa8329ec0c4d3aba3c03f19e1781d607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Thu, 17 Apr 2025 16:20:13 +0800 Subject: [PATCH 23/35] =?UTF-8?q?feat:=20=E6=8F=90=E4=BA=A4=E4=B8=8A?= =?UTF-8?q?=E9=97=A8=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 946ca2d..e9a1510 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -199,14 +199,7 @@ class OrderDispatchService extends BaseService */ public function appointmentTime(int $workerId, int $orderDispatchId, string $planTime) { - $orderDispatch = $this->getOrderDispatchModel() - ->where('id', $orderDispatchId) - ->where('worker_id', $workerId) - ->find(); - if (!$orderDispatch) { - $this->apiError('订单不存在'); - } - + $orderDispatch = $this->getOrderDispatchInfo($workerId, $orderDispatchId); $orderDispatch->status = OrderDispatch::STATUS_PLANIT; $orderDispatch->plan_time = $planTime; $orderDispatch->save(); @@ -219,6 +212,37 @@ class OrderDispatchService extends BaseService return true; } + + public function arrivedOnSite(int $workerId, int $orderDispatchId, string $img) + { + $time = datetime(time()); + $orderDispatch = $this->getOrderDispatchInfo($workerId, $orderDispatchId); + $orderDispatch->status = OrderDispatch::STATUS_CLOCK; + $orderDispatch->arrive_image = $img; + $orderDispatch->arrive_time = $time; + $orderDispatch->save(); + + //派单状态变更 + $orderDispatchChangeParams = [ + 'dispatch' => $orderDispatch, + 'remark' => '师傅已上门,上门时间:' . $time, + ]; + Hook::listen('order_dispatch_change', $orderDispatchChangeParams); + + return true; + } + + private function getOrderDispatchInfo(int $workerId, int $orderDispatchId) { + $res = $this->getOrderDispatchModel() + ->where('id', $orderDispatchId) + ->where('worker_id', $workerId) + ->find(); + if (!$res) { + $this->apiError('订单不存在'); + } + + return $res; + } } From da72759c523c9f698b464feb11a0e63a24a12c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Thu, 17 Apr 2025 16:25:53 +0800 Subject: [PATCH 24/35] =?UTF-8?q?feat:=20=E6=8F=90=E4=BA=A4=E4=B8=8A?= =?UTF-8?q?=E9=97=A8=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index e9a1510..d70e4f7 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -213,6 +213,13 @@ class OrderDispatchService extends BaseService return true; } + /** + * 完成上门 + * @param int $workerId 师傅id + * @param int $orderDispatchId 派单id + * @param string $img 上门图片 + * @return true + */ public function arrivedOnSite(int $workerId, int $orderDispatchId, string $img) { $time = datetime(time()); @@ -232,6 +239,11 @@ class OrderDispatchService extends BaseService return true; } + /** + * 获取订单信息 + * @param int $workerId 师傅id + * @param int $orderDispatchId 派单id + */ private function getOrderDispatchInfo(int $workerId, int $orderDispatchId) { $res = $this->getOrderDispatchModel() ->where('id', $orderDispatchId) From a79064eedc96e5d8fd83895750db2098fae647c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Thu, 17 Apr 2025 16:38:19 +0800 Subject: [PATCH 25/35] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/worker/controller/OrderDispatch.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index 49e8016..f0a4293 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -108,6 +108,18 @@ class OrderDispatch extends WorkerApi $res = $this->getOrderDispatchService()->arrivedOnSite($this->user['id'], $params['order_dispatch_id'], $params['img']); $this->success('操作成功', $res); } + + public function completeService() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.completeService'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderDispatchService()->completeService($this->user['id'], $params); + $this->success('操作成功', $res); + } } From f6dfba93f71e197169e0695c9312369be5c9f443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sat, 19 Apr 2025 14:32:49 +0800 Subject: [PATCH 26/35] =?UTF-8?q?feat:=20=E5=9B=BE=E7=89=87=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E5=BC=A0=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 17 ++++++++++++++--- application/worker/controller/OrderDispatch.php | 2 +- application/worker/validate/OrderDispatch.php | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index d70e4f7..841ae21 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -217,15 +217,15 @@ class OrderDispatchService extends BaseService * 完成上门 * @param int $workerId 师傅id * @param int $orderDispatchId 派单id - * @param string $img 上门图片 + * @param string $images 上门图片 * @return true */ - public function arrivedOnSite(int $workerId, int $orderDispatchId, string $img) + public function arrivedOnSite(int $workerId, int $orderDispatchId, string $images) { $time = datetime(time()); $orderDispatch = $this->getOrderDispatchInfo($workerId, $orderDispatchId); $orderDispatch->status = OrderDispatch::STATUS_CLOCK; - $orderDispatch->arrive_image = $img; + $orderDispatch->arrive_images = $this->removeStrCdnUrl($images); $orderDispatch->arrive_time = $time; $orderDispatch->save(); @@ -239,6 +239,17 @@ class OrderDispatchService extends BaseService return true; } + /** + * 移出字符串中的 cdnUrl + * @param string $str + * @return string + */ + private function removeStrCdnUrl(string $str): string + { + $cdnUrl = cdnurl('', true); + return str_replace($cdnUrl, '', $str); + } + /** * 获取订单信息 * @param int $workerId 师傅id diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index f0a4293..0e919da 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -105,7 +105,7 @@ class OrderDispatch extends WorkerApi $this->error($validate); } - $res = $this->getOrderDispatchService()->arrivedOnSite($this->user['id'], $params['order_dispatch_id'], $params['img']); + $res = $this->getOrderDispatchService()->arrivedOnSite($this->user['id'], $params['order_dispatch_id'], $params['images']); $this->success('操作成功', $res); } diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index 9b472c9..ec607ab 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -11,7 +11,7 @@ class OrderDispatch extends Validate 'order_dispatch_id|订单派单id' => 'require|number', 'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all', 'plan_time|预约时间' => 'require|date', - 'img|上门图片' => 'require|max:300', + 'images|上门图片' => 'require|max:3000', ]; protected $message = [ @@ -23,6 +23,6 @@ class OrderDispatch extends Validate 'workbenchOrderList' => ['workbench_type'], 'info' => ['order_dispatch_id'], 'appointmentTime' => ['order_dispatch_id', 'plan_time'], - 'arrivedOnSite' => ['order_dispatch_id', 'img'], + 'arrivedOnSite' => ['order_dispatch_id', 'images'], ]; } From ebe4f9549a43eabff55afad0821b9b502eba1c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sat, 19 Apr 2025 21:40:42 +0800 Subject: [PATCH 27/35] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/BaseService.php | 9 ++++ application/services/OrderDispatchService.php | 50 ++++++++++++++++++- .../worker/controller/OrderDispatch.php | 4 ++ application/worker/validate/OrderDispatch.php | 7 +++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/application/services/BaseService.php b/application/services/BaseService.php index 1345887..7e8801f 100644 --- a/application/services/BaseService.php +++ b/application/services/BaseService.php @@ -4,6 +4,7 @@ namespace app\services; use app\api\library\ApiException; use app\common\controller\WorkerApi; +use app\common\Logic\OrderLogic; use app\common\model\Worker; use think\Log; @@ -101,5 +102,13 @@ class BaseService return app(Order::class, true); } + /** + * @return OrderLogic + */ + protected function getOrderLogic() + { + return app(OrderLogic::class); + } + //{%add function code%} } diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 841ae21..59f1c72 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -240,7 +240,7 @@ class OrderDispatchService extends BaseService } /** - * 移出字符串中的 cdnUrl + * 移除字符串中的 cdnUrl * @param string $str * @return string */ @@ -266,6 +266,54 @@ class OrderDispatchService extends BaseService return $res; } + + /** + * @param int $workerId 师傅id + * @param array $params 请求参数 + * @return void + */ + public function completeService(int $workerId, array $params) + { + Db::startTrans(); + try { + $time = datetime(time()); + $orderDispatch = $this->getOrderDispatchInfo($workerId, $params['order_dispatch_id']); + $orderDispatch->status = OrderDispatch::STATUS_FINISH; + $orderDispatch->images = $this->removeStrCdnUrl($params['complete_images']); + $orderDispatch->image = $this->removeStrCdnUrl($params['payment_image']); + $orderDispatch->offline_total_type = $params['offline_total_type']; + $orderDispatch->finish_time = $time; + + //线下尾款 + if ($params['final_payment_method'] == 1) { + $orderDispatch->total = $params['amount']; + } + + //线上尾款 + if ($params['final_payment_method'] == 2) { + $orderDispatch->online_total = $params['amount']; + } + + $orderDispatch->save(); + + //派单状态变更 + $orderDispatchChangeParams = [ + 'dispatch' => $orderDispatch, + 'remark' => '师傅已完成服务,完成时间:' . $time, + ]; + Hook::listen('order_dispatch_change', $orderDispatchChangeParams); + + //修改订单状态 + $orderDispatchInfo = OrderDispatch::get($params['order_dispatch_id']); + $roleInfo = ['role' => 2, 'auth' => $this->getWorkerModel()->find($workerId), 'remark' => '师傅完成服务']; + $this->getOrderLogic()->dispachFinishAfter($orderDispatchInfo, $roleInfo); + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + $this->apiError('操作失败', $e); + } + + } } diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index 0e919da..01fc107 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -117,6 +117,10 @@ class OrderDispatch extends WorkerApi $this->error($validate); } + if ($params['final_payment_method'] == 1 && empty($params['offline_total_type'])) { + $this->error('线下尾款需选择尾款收款方'); + } + $res = $this->getOrderDispatchService()->completeService($this->user['id'], $params); $this->success('操作成功', $res); } diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index ec607ab..92aad02 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -12,6 +12,12 @@ class OrderDispatch extends Validate 'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all', 'plan_time|预约时间' => 'require|date', 'images|上门图片' => 'require|max:3000', + + 'complete_images|完成图片' => 'require|max:3000', + 'final_payment_method|收款方式' => 'require|in:1,2', + 'amount|收款金额' => 'require|number|between:0,10000000', + 'payment_image|收款图片' => 'require|max:255', + 'offline_total_type|尾款收款方' => 'in:1,2', ]; protected $message = [ @@ -24,5 +30,6 @@ class OrderDispatch extends Validate 'info' => ['order_dispatch_id'], 'appointmentTime' => ['order_dispatch_id', 'plan_time'], 'arrivedOnSite' => ['order_dispatch_id', 'images'], + 'completeService' => ['order_dispatch_id', 'complete_images', 'offline_total_type', 'amount', 'payment_image', 'offline_total_type'], ]; } From 6b6fb2cf8628b7f130659994ae1ece5461e0cda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sat, 19 Apr 2025 23:44:07 +0800 Subject: [PATCH 28/35] =?UTF-8?q?feat:=20=E5=B8=88=E5=82=85=E6=8B=92?= =?UTF-8?q?=E6=8E=A5=E6=94=AF=E6=8C=81=E5=A1=AB=E5=86=99=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/OrderDispatch.php | 10 ++++ application/services/OrderDispatchService.php | 53 ++++++++++++++++--- .../worker/controller/OrderDispatch.php | 2 +- application/worker/validate/OrderDispatch.php | 3 +- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/application/common/model/OrderDispatch.php b/application/common/model/OrderDispatch.php index 362f9eb..72ce066 100644 --- a/application/common/model/OrderDispatch.php +++ b/application/common/model/OrderDispatch.php @@ -18,4 +18,14 @@ class OrderDispatch extends Model { return $this->belongsTo(Order::class,'order_id', 'id'); } + + public function getArriveImagesAttr($val) + { + $images = explode(',', $val); + foreach ($images as $k => $v) { + $images[$k] = cdnurl($v, true); + } + + return $images; + } } diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 59f1c72..8b0c25a 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -103,12 +103,14 @@ class OrderDispatchService extends BaseService /** * 师傅接单/拒接 * @param int $workerId 师傅id - * @param int $orderDispatchId 派单id - * @param string $type 类型:accept=接单,reject=拒接 + * @param array $params 请求参数 * @return true */ - public function orderConfirm(int $workerId, int $orderDispatchId, string $type) + public function orderConfirm(int $workerId, array $params) { + $orderDispatchId = $params['order_dispatch_id']; + $type = $params['type']; + $orderDispatch = $this->getOrderDispatchModel() ->where('worker_id', $workerId) ->where('id', $orderDispatchId) @@ -128,6 +130,15 @@ class OrderDispatchService extends BaseService try { //接单 $orderDispatch->status = $orderDispatchStatus; + + //拒接原因 + if ($type == 'reject') { + if (empty($params['reject_reason'])) { + $this->apiError('请输入拒接原因'); + } + $orderDispatch->reject_reason = $params['reject_reason']; + } + $orderDispatch->save(); $orderDispatchChangeParams = [ @@ -173,15 +184,45 @@ class OrderDispatchService extends BaseService */ public function dispatchInfo(int $workerId, int $orderDispatchId) { + $orderFields = [ + 'id', + 'order_no', + 'item_id', + 'item_title', + 'receive_type', + 'address', + 'lng', + 'lat', + 'plan_time', + 'online_amount', + 'discount_amount', + 'area_id', + 'customer', + 'tel', + ]; + $orderDispatchFields = [ + 'id', + 'order_id', + 'status', + 'remark', + 'create_time', + 'total', + 'online_total', + 'is_receipt', + 'plan_time', + 'reject_reason', + 'arrive_images', + 'arrive_time', + ]; $res = $this->getOrderDispatchModel() - ->with(['orderInfo' => function ($query) { + ->with(['orderInfo' => function ($query) use ($orderFields) { $query->with(['area' => function ($query) { $query->field('id,area_code,merge_name'); - }])->field('id,order_no,item_id,item_title,receive_type,address,lng,lat,plan_time,online_amount,discount_amount,area_id,customer,tel'); + }])->field($orderFields); }]) ->where('id', $orderDispatchId) ->where('worker_id', $workerId) - ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'total', 'online_total', 'is_receipt', 'plan_time']) + ->field($orderDispatchFields) ->find(); if (!$res) { $this->apiError('订单不存在'); diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index 01fc107..13af53c 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -73,7 +73,7 @@ class OrderDispatch extends WorkerApi $this->error($validate); } - $res = $this->getOrderDispatchService()->orderConfirm($this->user['id'], $params['order_dispatch_id'], $params['type']); + $res = $this->getOrderDispatchService()->orderConfirm($this->user['id'], $params); $this->success('操作成功', $res); } diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index 92aad02..5103b78 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -18,6 +18,7 @@ class OrderDispatch extends Validate 'amount|收款金额' => 'require|number|between:0,10000000', 'payment_image|收款图片' => 'require|max:255', 'offline_total_type|尾款收款方' => 'in:1,2', + 'reject_reason|拒接原因' => 'max:255', ]; protected $message = [ @@ -25,7 +26,7 @@ class OrderDispatch extends Validate ]; protected $scene = [ - 'orderConfirm' => ['type', 'order_dispatch_id'], + 'orderConfirm' => ['type', 'order_dispatch_id', 'reject_reason'], 'workbenchOrderList' => ['workbench_type'], 'info' => ['order_dispatch_id'], 'appointmentTime' => ['order_dispatch_id', 'plan_time'], From fe91ab536521526f6271b0f3b24e6cd6295468f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sun, 20 Apr 2025 08:46:05 +0800 Subject: [PATCH 29/35] =?UTF-8?q?feat:=20=E6=8B=92=E6=8E=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/OrderDispatch.php | 30 +++++++++++++++++++ application/services/OrderDispatchService.php | 6 +++- application/worker/validate/OrderDispatch.php | 4 +-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/application/common/model/OrderDispatch.php b/application/common/model/OrderDispatch.php index 72ce066..4de16f0 100644 --- a/application/common/model/OrderDispatch.php +++ b/application/common/model/OrderDispatch.php @@ -28,4 +28,34 @@ class OrderDispatch extends Model return $images; } + + public function getImagesAttr($val) + { + $images = explode(',', $val); + foreach ($images as $k => $v) { + $images[$k] = cdnurl($v, true); + } + + return $images; + } + + public function getImageAttr($val) + { + return cdnurl($val, true); + } } + + + + + + + + + + + + + + + diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 8b0c25a..f6d3973 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -156,7 +156,7 @@ class OrderDispatchService extends BaseService $orderChangeParams['order'] = $order; $orderChangeParams['role'] = 2; $orderChangeParams['auth'] = $this->getWorkerModel()->find($orderDispatch->worker_id); - $orderChangeParams['remark'] = '任务被师傅拒接[OrderDispatchId:' . $orderDispatch->id . '],订单状态回退'; + $orderChangeParams['remark'] = "任务被师傅拒接[OrderDispatchId:{$orderDispatch->id},原因为:{$params['reject_reason']},订单状态回退"; Hook::listen('order_change', $orderChangeParams); } @@ -213,6 +213,10 @@ class OrderDispatchService extends BaseService 'reject_reason', 'arrive_images', 'arrive_time', + 'images', + 'image', + 'finish_time', + 'offline_total_type', ]; $res = $this->getOrderDispatchModel() ->with(['orderInfo' => function ($query) use ($orderFields) { diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index 5103b78..c4b6ced 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -17,8 +17,8 @@ class OrderDispatch extends Validate 'final_payment_method|收款方式' => 'require|in:1,2', 'amount|收款金额' => 'require|number|between:0,10000000', 'payment_image|收款图片' => 'require|max:255', - 'offline_total_type|尾款收款方' => 'in:1,2', - 'reject_reason|拒接原因' => 'max:255', + 'offline_total_type|尾款收款方' => 'in:0,1,2', + 'reject_reason|拒接原因' => 'max:100', ]; protected $message = [ From 84343e17e2efce0100dcb291856d5825ad840bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sun, 20 Apr 2025 09:37:25 +0800 Subject: [PATCH 30/35] =?UTF-8?q?feat:=20=E5=BC=82=E5=B8=B8=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Abnormal.php | 18 ++++++++++++++++++ application/services/AbnormalService.php | 18 ++++++++++++++++++ application/services/BaseService.php | 17 +++++++++++++++++ application/worker/controller/Abnormal.php | 16 ++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 application/common/model/Abnormal.php create mode 100644 application/services/AbnormalService.php create mode 100644 application/worker/controller/Abnormal.php diff --git a/application/common/model/Abnormal.php b/application/common/model/Abnormal.php new file mode 100644 index 0000000..af459df --- /dev/null +++ b/application/common/model/Abnormal.php @@ -0,0 +1,18 @@ +getAbnormalModel() + ->where('type', 1) + ->order('sort', 'desc') + ->field([ + 'id', + 'title', + ]) + ->select(); + } +} diff --git a/application/services/BaseService.php b/application/services/BaseService.php index 7e8801f..1752016 100644 --- a/application/services/BaseService.php +++ b/application/services/BaseService.php @@ -11,6 +11,7 @@ use think\Log; use app\common\model\WorkerVendor; use app\common\model\OrderDispatch; use app\common\model\Order; +use app\common\model\Abnormal; //{%add use model%} class BaseService @@ -110,5 +111,21 @@ class BaseService return app(OrderLogic::class); } + /** + * @return AbnormalService + */ + protected function getAbnormalService() + { + return app(AbnormalService::class); + } + + /** + * @return Abnormal + */ + protected function getAbnormalModel() + { + return app(Abnormal::class, true); + } + //{%add function code%} } diff --git a/application/worker/controller/Abnormal.php b/application/worker/controller/Abnormal.php new file mode 100644 index 0000000..3409469 --- /dev/null +++ b/application/worker/controller/Abnormal.php @@ -0,0 +1,16 @@ +getAbnormalService()->findAll(); + $this->success('操作成功', $res); + } +} From 72483a53be6a70d401e5d13c867869a3caef9b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Sun, 20 Apr 2025 14:02:17 +0800 Subject: [PATCH 31/35] =?UTF-8?q?feat:=20=E8=AE=A2=E5=8D=95=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/OrderAbnormal.php | 18 +++++++++++++++ application/services/BaseService.php | 17 ++++++++++++++ application/services/OrderAbnormalService.php | 8 +++++++ .../worker/controller/OrderAbnormal.php | 22 +++++++++++++++++++ application/worker/validate/OrderAbnormal.php | 8 +++++++ 5 files changed, 73 insertions(+) create mode 100644 application/common/model/OrderAbnormal.php create mode 100644 application/services/OrderAbnormalService.php create mode 100644 application/worker/controller/OrderAbnormal.php create mode 100644 application/worker/validate/OrderAbnormal.php diff --git a/application/common/model/OrderAbnormal.php b/application/common/model/OrderAbnormal.php new file mode 100644 index 0000000..2c2968c --- /dev/null +++ b/application/common/model/OrderAbnormal.php @@ -0,0 +1,18 @@ +request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderAbnormal::class . '.create'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderAbnormalService()->create($this->user['id'], $params); + $this->success('操作成功', $res); + } +} diff --git a/application/worker/validate/OrderAbnormal.php b/application/worker/validate/OrderAbnormal.php new file mode 100644 index 0000000..bf7e099 --- /dev/null +++ b/application/worker/validate/OrderAbnormal.php @@ -0,0 +1,8 @@ + Date: Sun, 20 Apr 2025 22:51:50 +0800 Subject: [PATCH 32/35] =?UTF-8?q?feat:=20=E4=B8=8A=E6=8A=A5=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/OrderAbnormal.php | 3 + application/services/OrderAbnormalService.php | 75 +++++++++++++++++++ .../worker/controller/OrderAbnormal.php | 33 ++++++++ application/worker/validate/OrderAbnormal.php | 23 +++++- 4 files changed, 131 insertions(+), 3 deletions(-) diff --git a/application/common/model/OrderAbnormal.php b/application/common/model/OrderAbnormal.php index 2c2968c..62e67ba 100644 --- a/application/common/model/OrderAbnormal.php +++ b/application/common/model/OrderAbnormal.php @@ -15,4 +15,7 @@ class OrderAbnormal extends Model ]; + protected $autoWriteTimestamp = 'datetime'; + + protected $dateFormat = 'Y-m-d H:i:s'; } diff --git a/application/services/OrderAbnormalService.php b/application/services/OrderAbnormalService.php index cd05776..bf953eb 100644 --- a/application/services/OrderAbnormalService.php +++ b/application/services/OrderAbnormalService.php @@ -4,5 +4,80 @@ namespace app\services; class OrderAbnormalService extends BaseService { + /** + * 上报异常 + * @param int $workerId + * @param array $params + * @return bool + */ + public function create(int $workerId, array $params) + { + $data = $this->getOrderAbnormal($workerId, $params['order_id']); + if ($data) { + $this->apiError('您已上报过异常,请勿重复提交'); + } + $abnormal = $this->getAbnormalModel()->find($params['abnormal_id']); + if (!$abnormal) { + $this->apiError('异常原因不存在,请重新选择'); + } + + $worker = $this->getWorkerModel()->find($workerId); + + $model = $this->getOrderAbnormalModel(); + $model->order_id = $params['order_id']; + $model->status = 0; + $model->abnormal_id = $params['abnormal_id']; + $model->abnormal_title = $abnormal->title; + $model->detail = $params['detail']; + $model->type = 2; + $model->admin_user = $worker->name; + $model->admin_id = $workerId; + $model->save(); + + return true; + } + + /** + * 获取订单异常详情 + * @param int $workerId + * @param int $orderId + */ + public function getOrderAbnormal(int $workerId, int $orderId) + { + return $this->getOrderAbnormalModel() + ->where('order_id', $orderId) + ->where('admin_id', $workerId) + ->where('type', 2) + ->field([ + 'id', + 'order_id', + 'abnormal_id', + 'abnormal_title', + 'detail', + 'create_time', + ]) + ->find(); + } } + + + + + + + + + + + + + + + + + + + + + diff --git a/application/worker/controller/OrderAbnormal.php b/application/worker/controller/OrderAbnormal.php index 85e12a6..33ba4da 100644 --- a/application/worker/controller/OrderAbnormal.php +++ b/application/worker/controller/OrderAbnormal.php @@ -19,4 +19,37 @@ class OrderAbnormal extends WorkerApi $res = $this->getOrderAbnormalService()->create($this->user['id'], $params); $this->success('操作成功', $res); } + + public function info() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderAbnormal::class . '.info'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderAbnormalService()->getOrderAbnormal($this->user['id'], $params['order_id']); + $this->success('操作成功', $res ?: []); + } } + + + + + + + + + + + + + + + + + + + + + diff --git a/application/worker/validate/OrderAbnormal.php b/application/worker/validate/OrderAbnormal.php index bf7e099..0c635a6 100644 --- a/application/worker/validate/OrderAbnormal.php +++ b/application/worker/validate/OrderAbnormal.php @@ -2,7 +2,24 @@ namespace app\worker\validate; -class OrderAbnormal -{ +use think\Validate; -} \ No newline at end of file +class OrderAbnormal extends Validate +{ + protected $rule = [ + 'abnormal_id|异常原因' => 'require|number', + 'order_id|订单id' => 'require|number', + 'detail|异常详情' => 'require|max:200', + ]; + + protected $message = [ + 'abnormal_id.require' => '请选择异常原因', + 'detail.require' => '异常说明不能为空', + 'detail.max' => '异常说明不能超过 200 个字', + ]; + + protected $scene = [ + 'create' => ['abnormal_id', 'order_id', 'detail'], + 'info' => ['order_id'], + ]; +} From f68b3571fc5c07f32bcb82b616ffedb3bdcd48ec Mon Sep 17 00:00:00 2001 From: gcd Date: Sun, 20 Apr 2025 23:47:00 +0800 Subject: [PATCH 33/35] =?UTF-8?q?feat:=20=E5=B8=88=E5=82=85=E5=A4=87?= =?UTF-8?q?=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 22 +++++++++++++++++-- .../worker/controller/OrderDispatch.php | 16 ++++++++++++++ application/worker/validate/OrderDispatch.php | 2 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index f6d3973..1924969 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -205,6 +205,7 @@ class OrderDispatchService extends BaseService 'order_id', 'status', 'remark', + 'worker_remark', 'create_time', 'total', 'online_total', @@ -306,7 +307,7 @@ class OrderDispatchService extends BaseService ->where('worker_id', $workerId) ->find(); if (!$res) { - $this->apiError('订单不存在'); + $this->apiError('工单不存在'); } return $res; @@ -315,7 +316,7 @@ class OrderDispatchService extends BaseService /** * @param int $workerId 师傅id * @param array $params 请求参数 - * @return void + * @return bool */ public function completeService(int $workerId, array $params) { @@ -358,6 +359,23 @@ class OrderDispatchService extends BaseService $this->apiError('操作失败', $e); } + return true; + } + + /** + * 保存师傅备注 + * @param int $workerId 师傅id + * @param int $orderDispatchId 订单派单id + * @param string $workerRemark 备注信息 + * @return true + */ + public function saveWorkerRemark(int $workerId, int $orderDispatchId, string $workerRemark) + { + $orderDispatch = $this->getOrderDispatchInfo($workerId, $orderDispatchId); + $orderDispatch->worker_remark = $workerRemark; + $orderDispatch->save(); + + return true; } } diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index 13af53c..6f07222 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -124,6 +124,22 @@ class OrderDispatch extends WorkerApi $res = $this->getOrderDispatchService()->completeService($this->user['id'], $params); $this->success('操作成功', $res); } + + /** + * 保存师傅备注 + * @return void + */ + public function saveWorkerRemark() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\OrderDispatch::class . '.saveWorkerRemark'); + if ($validate !== true) { + $this->error($validate); + } + + $res = $this->getOrderDispatchService()->saveWorkerRemark($this->user['id'], $params['order_dispatch_id'], $params['worker_remark']); + $this->success('操作成功', $res); + } } diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index c4b6ced..0e01e33 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -19,6 +19,7 @@ class OrderDispatch extends Validate 'payment_image|收款图片' => 'require|max:255', 'offline_total_type|尾款收款方' => 'in:0,1,2', 'reject_reason|拒接原因' => 'max:100', + 'worker_remark|备注信息' => 'max:500', ]; protected $message = [ @@ -32,5 +33,6 @@ class OrderDispatch extends Validate 'appointmentTime' => ['order_dispatch_id', 'plan_time'], 'arrivedOnSite' => ['order_dispatch_id', 'images'], 'completeService' => ['order_dispatch_id', 'complete_images', 'offline_total_type', 'amount', 'payment_image', 'offline_total_type'], + 'saveWorkerRemark' => ['order_dispatch_id', 'worker_remark'], ]; } From 9762d89d4ec5b3452b2ac6870b76c17e585c5b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=9F=E5=B7=9D=E4=B8=9C?= Date: Mon, 21 Apr 2025 14:57:49 +0800 Subject: [PATCH 34/35] =?UTF-8?q?feat:=20=E5=B7=A5=E4=BD=9C=E5=8F=B0?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E8=AE=A2=E5=8D=95=E5=A2=9E=E5=8A=A0=E5=B7=B2?= =?UTF-8?q?=E6=8B=92=E6=8E=A5=E7=9A=84=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 1924969..96ec6f4 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -92,6 +92,7 @@ class OrderDispatchService extends BaseService $model->where('plan_time', '<=', date('Y-m-d 23:59:59', strtotime('+1 day'))); break; case 'all': + $status[] = OrderDispatch::STATUS_REFUSED; $status[] = OrderDispatch::STATUS_FINISH; $model->whereIn('status', $status); break; From 1fab1a1c3f30d8f98c45c2747bb5ebe00465a056 Mon Sep 17 00:00:00 2001 From: gcd Date: Mon, 21 Apr 2025 23:08:20 +0800 Subject: [PATCH 35/35] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=A4=87=E6=B3=A8=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/OrderDispatchService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 96ec6f4..7a9431e 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -200,6 +200,8 @@ class OrderDispatchService extends BaseService 'area_id', 'customer', 'tel', + 'remark', + 'detail', ]; $orderDispatchFields = [ 'id',