From 995d06ea1d9ee2b0076f9e20a0098e11cae62e93 Mon Sep 17 00:00:00 2001 From: hant Date: Sat, 31 May 2025 17:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/alisms/library/Alisms.php | 8 + application/admin/command/Test.php | 12 +- application/admin/controller/Order.php | 147 ++++++++++-------- .../admin/controller/SendMailLogic.php | 73 +++++++++ .../admin/controller/aftersales/Aftersale.php | 3 +- application/admin/lang/zh-cn/order.php | 1 + application/admin/model/Order.php | 12 +- application/admin/view/order/delete.html | 4 + public/assets/js/backend/order.js | 11 +- public/assets/js/backend/orders/invoice.js | 2 +- 10 files changed, 191 insertions(+), 82 deletions(-) create mode 100644 application/admin/controller/SendMailLogic.php diff --git a/addons/alisms/library/Alisms.php b/addons/alisms/library/Alisms.php index d01f25c..4894571 100644 --- a/addons/alisms/library/Alisms.php +++ b/addons/alisms/library/Alisms.php @@ -2,6 +2,8 @@ namespace addons\alisms\library; +use think\Db; + /** * 阿里大于SMS短信发送 */ @@ -91,6 +93,12 @@ class Alisms { $this->error = ''; $params = $this->_params(); + Db::name('sms_record')->insert([ + 'receiver' => $params['PhoneNumbers'], + 'content' => $params['TemplateParam'], + 'template_id' => $params['TemplateCode'], + ]); + return true; $params['Signature'] = $this->_signed($params); $response = $this->_curl($params); if ($response !== false) { diff --git a/application/admin/command/Test.php b/application/admin/command/Test.php index dd5210e..02d3fc6 100644 --- a/application/admin/command/Test.php +++ b/application/admin/command/Test.php @@ -4,6 +4,7 @@ namespace app\admin\command; use app\admin\addresmart\Address; use app\admin\controller\orders\DispatchLogic; +use app\admin\controller\SendMailLogic; use app\admin\model\Order; use app\admin\model\OrderDispatch; use app\admin\model\OrderReview; @@ -31,15 +32,10 @@ class Test extends Command protected function execute(Input $input, Output $output) { - $res = \app\common\library\Sms::notice('17381847364',[], 'start_worker'); - - $alisms = new \addons\alisms\library\Alisms(); - $ret = $alisms->mobile('13038128325') - ->template('SMS_487375365') - ->sign('超邦手') - ->send(); - +// $ret = SendMailLogic::sendToCustomStart('13038128325','今日的风儿','173xxxxxxxx'); + $ret = SendMailLogic::sendToCustomStop('17381847365'); dd($ret); +// dd($ret); } diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index fc005ca..9ee861f 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -43,7 +43,6 @@ class Order extends Backend parent::_initialize(); $this->model = new \app\admin\model\Order; $this->view->assign("statusList", $this->model->getStatusList()); - $sources = Db::name('source') ->where('status', 1) ->field(['id', 'title', 'key_word', 'pid']) @@ -196,7 +195,7 @@ class Order extends Backend return $this->view->fetch(); } $params = $this->request->post('row/a'); - $params = array_filter($params,function ($val){ + $params = array_filter($params, function ($val) { return $val != ''; }); if (empty($params)) { @@ -221,7 +220,7 @@ class Order extends Backend $sources = array_column($sources, 'title', 'id'); $params['source_shop'] = $sources[$params['source']] ?? null; - $params['item_title'] = $this->findElementByValue($this->itemsformattedTree,$params['item_id'] ?? null); + $params['item_title'] = $this->findElementByValue($this->itemsformattedTree, $params['item_id'] ?? null); $params['admin_id'] = ($params['admin_id'] ?? -1) == -1 ? $this->auth->id : $params['admin_id']; @@ -243,7 +242,7 @@ class Order extends Backend $hookparams['order'] = $this->model; $hookparams['role'] = 1; $hookparams['auth'] = $this->auth; - $hookparams['remark'] = $params['remark']??''; + $hookparams['remark'] = $params['remark'] ?? ''; Hook::listen('order_change', $hookparams); Db::commit(); @@ -297,7 +296,7 @@ class Order extends Backend $params['admin_id'] = $this->auth->id; } $params['source_shop'] = $sources[$params['source']] ?? null; - $params['item_title'] = $this->findElementByValue($this->itemsformattedTree,$params['item_id'] ?? null); + $params['item_title'] = $this->findElementByValue($this->itemsformattedTree, $params['item_id'] ?? null); // $params['create_time'] = date('Y-m-d H:i:s'); $params['update_time'] = date('Y-m-d H:i:s'); @@ -396,8 +395,8 @@ class Order extends Backend //日志 $hookParams = [ - 'dispatch' => (new OrderDispatch())->where('id', $res)->find(), - 'remark' => '自动派单,操作人:'.$this->auth->nickname, + 'dispatch' => (new OrderDispatch())->where('id', $res)->find(), + 'remark' => '自动派单,操作人:' . $this->auth->nickname, ]; Hook::listen('order_dispatch_change', $hookParams); @@ -417,19 +416,19 @@ class Order extends Backend $order = $this->model->where('id', $ids)->find(); - $area_id = substr($order->area_id,0,4); + $area_id = substr($order->area_id, 0, 4); - $res = Admin::where('area_ids','like','%'.$area_id.'%') + $res = Admin::where('area_ids', 'like', '%' . $area_id . '%') ->column('id'); $insert = []; - foreach ($res as $re){ - $insert [] = [ - 'to_id' => $re, - 'type' => 1, - 'title' => '订单报错通知', - 'content' => '【催单通知】您有一条订单号为'.$order->order_no.'的订单被催单,请立即派单!' + foreach ($res as $re) { + $insert [] = [ + 'to_id' => $re, + 'type' => 1, + 'title' => '订单报错通知', + 'content' => '【催单通知】您有一条订单号为' . $order->order_no . '的订单被催单,请立即派单!' ]; } $build = new Message(); @@ -445,12 +444,12 @@ class Order extends Backend if (false === $this->request->isPost()) { $order = $this->model->where('id', $ids)->find(); - $abnormals = model('abnormal')->where('type',3)->order('sort','desc')->select(); + $abnormals = model('abnormal')->where('type', 3)->order('sort', 'desc')->select(); $options = []; - foreach ($abnormals as $abnormal){ + foreach ($abnormals as $abnormal) { $options [] = $abnormal->toArray(); } - return $this->fetch('warning',['row' => $order,'options' => $options]); + return $this->fetch('warning', ['row' => $order, 'options' => $options]); } $params = $this->request->post('row/a'); @@ -462,20 +461,20 @@ class Order extends Backend $order = model('order')->get($params['order_id']); - $area_id = substr($order->area_id,0,4); + $area_id = substr($order->area_id, 0, 4); - $res = Admin::where('area_ids','like','%'.$area_id.'%') + $res = Admin::where('area_ids', 'like', '%' . $area_id . '%') ->column('id'); $message = $params['detail'] ?? ''; $insert = []; - foreach ($res as $re){ - $insert [] = [ - 'to_id' => $re, - 'type' => 1, - 'title' => '订单内容变更', - 'content' => '【订单内容变更】您有一条订单信息被修改,修改内容为:【'.$message.'】,请注意查收。' + foreach ($res as $re) { + $insert [] = [ + 'to_id' => $re, + 'type' => 1, + 'title' => '订单内容变更', + 'content' => '【订单内容变更】您有一条订单信息被修改,修改内容为:【' . $message . '】,请注意查收。' ]; } $build = new Message(); @@ -485,16 +484,17 @@ class Order extends Backend } - public function addAbnormal($ids = null){ + public function addAbnormal($ids = null) + { if (false === $this->request->isPost()) { - $abnormals = model('abnormal')->where('type',1)->order('sort','desc')->select(); + $abnormals = model('abnormal')->where('type', 1)->order('sort', 'desc')->select(); $abnormals_data = []; - foreach ($abnormals as $abnormal){ + foreach ($abnormals as $abnormal) { $abnormals_data [] = $abnormal->toArray(); } - $order = model('order')->get($ids); - return $this->fetch('abnormal',['row' => $order,'options'=>$abnormals_data]); + $order = model('order')->get($ids); + return $this->fetch('abnormal', ['row' => $order, 'options' => $abnormals_data]); } $params = $this->request->post('row/a'); if (empty($params)) { @@ -521,10 +521,10 @@ class Order extends Backend ]; Message::create([ - 'to_id' => $order->admin_id, - 'type' => 1, - 'title' => '订单报错通知', - 'content' => '【订单报错通知】您有一条订单号为'.$order->order_no.'的订单订单信息录入错误,请前往报错订单界面进行查看,并立即处理!' + 'to_id' => $order->admin_id, + 'type' => 1, + 'title' => '订单报错通知', + 'content' => '【订单报错通知】您有一条订单号为' . $order->order_no . '的订单订单信息录入错误,请前往报错订单界面进行查看,并立即处理!' ]); $result = \model('order_abnormal')->insert($insert); @@ -540,16 +540,17 @@ class Order extends Backend } - public function delete($ids = null){ + public function delete($ids = null) + { if (false === $this->request->isPost()) { - $options = \model('abnormal')->where('type',2)->select(); + $options = \model('abnormal')->where('type', 2)->select(); $op = []; - foreach ($options as $option){ - $op[] = ['id' =>$option->id,'title'=>$option->title]; + foreach ($options as $option) { + $op[] = ['id' => $option->id, 'title' => $option->title]; } - $order = model('order')->get($ids); - return $this->fetch('delete',['row' => $order,'options'=>$op]); + $order = model('order')->get($ids); + return $this->fetch('delete', ['row' => $order, 'options' => $op]); } $params = $this->request->post('row/a'); if (empty($params)) { @@ -557,51 +558,62 @@ class Order extends Backend } $params = $this->preExcludeFields($params); + $send_mail = $params['notify'] ?? false; $result = false; Db::startTrans(); + $order = model('order')->get($params['order_id'], ['dispatch']); + if (!$order) { + $this->error('Not Find'); + } + try { - $order = model('order')->get($params['order_id'],['dispatch']); - if (!$order){ - $this->error('Not Find'); - } + $params['status'] = \app\admin\model\Order::STATUS_CANCEL; + + unset($params['notify']); + $result = $order->allowField(true)->save($params); - if(!empty($order->dispatch)){ + if (!empty($order->dispatch->id)) { $orderLogic = new OrderLogic(); - $orderLogic->cancelOrderDispatch($order->dispatch,$this->auth,'订单被取消',false); + $orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false); + //日志 + $hookparams['order'] = $order; + $hookparams['role'] = 1; + $hookparams['auth'] = $this->auth; + $hookparams['remark'] = $params['remark'] ?? ''; + Hook::listen('order_change', $hookparams); } - - //日志 - $hookparams['order'] = $order; - $hookparams['role'] = 1; - $hookparams['auth'] = $this->auth; - $hookparams['remark'] = $params['remark']??''; - Hook::listen('order_change', $hookparams); - Db::commit(); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } + if ($result === false) { $this->error(__('No rows were inserted')); } + + if ($send_mail) { + SendMailLogic::sendToCustomStop($order->tel); + } + $this->success(); } - public function send($ids = null){ + public function send($ids = null) + { if (false === $this->request->isPost()) { $options = \model('admin')->select(); $op = []; - foreach ($options as $option){ - $op[] = ['id' =>$option->id,'title'=>$option->nickname]; + foreach ($options as $option) { + $op[] = ['id' => $option->id, 'title' => $option->nickname]; } - $order = model('order')->get($ids); - return $this->fetch('delete',['row' => $order,'options'=>$op]); + $order = model('order')->get($ids); + return $this->fetch('delete', ['row' => $order, 'options' => $op]); } $params = $this->request->post('row/a'); if (empty($params)) { @@ -614,7 +626,7 @@ class Order extends Backend Db::startTrans(); try { $order = model('order')->get($params['order_id']); - if (!$order){ + if (!$order) { $this->error('Not Find'); } $params['status'] = \app\admin\model\Order::STATUS_CANCEL; @@ -660,6 +672,7 @@ class Order extends Backend // 重新索引数组 return array_values($filtered_codes); } + /** * 编辑 * @@ -668,10 +681,11 @@ class Order extends Backend * @throws DbException * @throws \think\Exception */ - public function invoice($ids = null){ + public function invoice($ids = null) + { if (false === $this->request->isPost()) { - $order = model('order')->get($ids); - return $this->fetch('order/invoice/add',['row' => $order]); + $order = model('order')->get($ids); + return $this->fetch('order/invoice/add', ['row' => $order]); } $params = $this->request->post('row/a'); if (empty($params)) { @@ -688,7 +702,7 @@ class Order extends Backend $params['invoice_method'] = 1; $result = (new Invoice())->allowField(true)->save($params); Db::commit(); - } catch (ValidateException|PDOException|Exception $e) { + } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -698,7 +712,8 @@ class Order extends Backend $this->success(); } - function findElementByValue($data, $targetValue, $path = []) { + function findElementByValue($data, $targetValue, $path = []) + { foreach ($data as $item) { // 将当前节点的 label 添加到路径中 $newPath = array_merge($path, [$item['label']]); diff --git a/application/admin/controller/SendMailLogic.php b/application/admin/controller/SendMailLogic.php new file mode 100644 index 0000000..b7dd331 --- /dev/null +++ b/application/admin/controller/SendMailLogic.php @@ -0,0 +1,73 @@ +mobile($toTel) + ->template($config['template']['start_worker']) + ->param([]) + ->send(); + return $result; + } + + /** + * 给客户接单的信息 + * @param $tel + * @return bool + */ + public static function sendToCustomStart($toTel,$work_name,$work_tel) + { + $config = get_addon_config('alisms'); + if (!isset($config['template']['start_custom'])) { + return false; + } + $alisms = new \addons\alisms\library\Alisms(); + $result = $alisms->mobile($toTel) + ->template($config['template']['start_custom']) + ->param([ + 'name' => $work_name, + 'phone' => $work_tel + ]) + ->send(); + return $result; + } + + + /** + * 给客户取消订单的信息 + * @param $tel + * @return bool + */ + public static function sendToCustomStop($toTel) + { + $config = get_addon_config('alisms'); + if (!isset($config['template']['stop_custom'])) { + return false; + } + $alisms = new \addons\alisms\library\Alisms(); + $result = $alisms->mobile($toTel) + ->template($config['template']['stop_custom']) + ->param() + ->send(); + return $result; + } + + +} \ No newline at end of file diff --git a/application/admin/controller/aftersales/Aftersale.php b/application/admin/controller/aftersales/Aftersale.php index 5a1d763..2124029 100644 --- a/application/admin/controller/aftersales/Aftersale.php +++ b/application/admin/controller/aftersales/Aftersale.php @@ -175,12 +175,13 @@ class Aftersale extends Backend Message::create([ 'to_id' => $params['dispatch_admin_id'], 'type' => 1, - 'title' => '订单报错通知', + 'title' => '售后申请通知', 'content' => '【售后申请通知】您有一条售后申请待处理,请前往订单售后界面进行处理!' ]); $result = $this->model->allowField(true)->save($params); $order->aftersale_id = $this->model->id; + $order->status = Order::STATUS_AFTERSALE; $order->save(); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { diff --git a/application/admin/lang/zh-cn/order.php b/application/admin/lang/zh-cn/order.php index 8b92b5f..f6a88cb 100644 --- a/application/admin/lang/zh-cn/order.php +++ b/application/admin/lang/zh-cn/order.php @@ -21,6 +21,7 @@ return [ 'Status 50' => '待结算', 'Set status to 50' => '设为待结算', 'Status 60' => '已完成', + 'Status 70' => '售后', 'Set status to 60' => '设为已完成', 'Status -10' => '取消', 'Set status to -10' => '设为取消', diff --git a/application/admin/model/Order.php b/application/admin/model/Order.php index 36da951..ad9560b 100644 --- a/application/admin/model/Order.php +++ b/application/admin/model/Order.php @@ -55,18 +55,23 @@ class Order extends Model const STATUS_CHECKONCE = 41; //审核未通过 const STATUS_AUDITING = 50; //审核中 const STATUS_FINISHED = 60; //已完成 + const STATUS_AFTERSALE= 70; //已完成 const STATUS_CANCEL = -10; //取消 + public function getStatusList() { return ['0' => __('Status 0'),'10' => __('Status 10'), '20' => __('Status 20'), //'30' => __('Status 30'), '40' => __('Status 40'), '41' => __('Status 41'), - '50' => __('Status 50'), '60' => __('Status 60'), '-10' => __('Status -10')]; + '50' => __('Status 50'), + '60' => __('Status 60'), + '70' => __('Status 70'), + '-10' => __('Status -10')]; } @@ -186,6 +191,11 @@ class Order extends Model return $this->belongsTo(Admin::class,'admin_id',); } + public function admin(){ + return $this->belongsTo(Admin::class,'admin_id',joinType: 'left') + ->setEagerlyType(0); + } + public function item(){ return $this->belongsTo(Item::class,'item_id',); } diff --git a/application/admin/view/order/delete.html b/application/admin/view/order/delete.html index ac16650..c34efc6 100644 --- a/application/admin/view/order/delete.html +++ b/application/admin/view/order/delete.html @@ -31,6 +31,10 @@ +
+ +
+