ServiceWorkController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\tenantapi\controller\works;
  15. use app\tenantapi\controller\BaseAdminController;
  16. use app\tenantapi\lists\works\ServiceWorkLists;
  17. use app\tenantapi\logic\master_worker\MasterWorkerLogic;
  18. use app\tenantapi\logic\works\ServiceWorkLogic;
  19. use app\tenantapi\validate\works\ServiceWorkValidate;
  20. use app\api\logic\ServiceOrderLogic;
  21. /**
  22. * ServiceWork控制器
  23. * Class WorksController
  24. * @package app\tenantapi\controller\works
  25. */
  26. class ServiceWorkController extends BaseAdminController
  27. {
  28. /**
  29. * @notes 获取列表
  30. * @return \think\response\Json
  31. * @author likeadmin
  32. * @date 2024/07/10 15:06
  33. */
  34. public function lists()
  35. {
  36. return $this->dataLists(new ServiceWorkLists());
  37. }
  38. /**
  39. * @notes 编辑
  40. * @return \think\response\Json
  41. * @author likeadmin
  42. * @date 2024/07/10 15:06
  43. */
  44. public function edit()
  45. {
  46. $params = (new ServiceWorkValidate())->post()->goCheck('edit');
  47. $workDetail = ServiceWorkLogic::detail($params);
  48. $result = ServiceWorkLogic::edit($params);
  49. if (true === $result) {
  50. if(strtotime($workDetail['appointment_time']) !== strtotime($params['appointment_time']) && !empty($workDetail['master_worker_id'])){
  51. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  52. // 修改预约时间通知【给用户的通知】
  53. $res = event('Notice', [
  54. 'scene_id' => 117,
  55. 'params' => [
  56. 'user_id' => $workDetail['user_id'],
  57. 'date' => $params['appointment_time'],
  58. 'tel' => asteriskString($masterDetail['mobile']),
  59. ]
  60. ]);
  61. // 修改预约时间通知【给工程师的通知,仅限公众号】
  62. $res = event('Notice', [
  63. 'scene_id' => 118,
  64. 'params' => [
  65. 'user_id' => $workDetail['master_worker_id'],
  66. 'order_id' => $workDetail['id'],
  67. 'thing4' => $workDetail['title'],
  68. 'time5' => $workDetail['appointment_time'],
  69. 'time6' => $params['appointment_time'],
  70. 'thing11' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  71. 'phone_number8' => asteriskString($workDetail['mobile']),
  72. ]
  73. ]);
  74. }
  75. return $this->success('编辑成功', [], 1, 1);
  76. }
  77. return $this->fail(ServiceWorkLogic::getError());
  78. }
  79. /**
  80. * @notes 删除
  81. * @return \think\response\Json
  82. * @author likeadmin
  83. * @date 2024/07/10 15:06
  84. */
  85. public function delete()
  86. {
  87. $params = (new ServiceWorkValidate())->post()->goCheck('delete');
  88. $result = ServiceWorkLogic::edit($params);
  89. if (true === $result) {
  90. return $this->success('编辑成功', [], 1, 1);
  91. }
  92. return $this->success('分配成功', [], 1, 1);
  93. }
  94. /**
  95. * @notes 获取详情
  96. * @return \think\response\Json
  97. * @author likeadmin
  98. * @date 2024/07/10 15:06
  99. */
  100. public function detail()
  101. {
  102. $params = (new ServiceWorkValidate())->goCheck('detail');
  103. $result = ServiceWorkLogic::detail($params);
  104. return $this->data($result);
  105. }
  106. public function allocateWorker()
  107. {
  108. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  109. $result = ServiceWorkLogic::allocateWorker($params,$this->adminInfo);
  110. if (true === $result) {
  111. // 工程师派单通知【给工程师的通知】【公众号通知,不发短信】
  112. $workDetail = ServiceWorkLogic::detail($params);
  113. $res = event('Notice', [
  114. 'scene_id' => 113,
  115. 'params' => [
  116. 'user_id' => $params['master_worker_id'],
  117. 'order_id' => $params['id'],
  118. 'thing9' => $workDetail['title'],
  119. 'time7' => $workDetail['appointment_time'],
  120. 'thing8' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  121. 'phone_number6' => asteriskString($workDetail['mobile']),
  122. ]
  123. ]);
  124. return $this->success('分配工程师成功', [], 1, 1);
  125. }
  126. return $this->fail(ServiceWorkLogic::getError());
  127. }
  128. public function cancelWorker()
  129. {
  130. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  131. $result = ServiceWorkLogic::cancel($params);
  132. if (true === $result) {
  133. return $this->success('取消工单成功!', [], 1, 1);
  134. }
  135. return $this->fail(ServiceWorkLogic::getError());
  136. }
  137. public function settlementMaster()
  138. {
  139. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  140. $result = ServiceWorkLogic::settlement($params);
  141. if (true === $result) {
  142. return $this->success('操作成功!', [], 1, 1);
  143. }
  144. return $this->fail(ServiceWorkLogic::getError());
  145. }
  146. public function notApproved()
  147. {
  148. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  149. $result = ServiceWorkLogic::notApproved($params);
  150. if (true === $result) {
  151. return $this->success('操作成功!', [], 1, 1);
  152. }
  153. return $this->fail(ServiceWorkLogic::getError());
  154. }
  155. public function cancelAllocation()
  156. {
  157. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  158. $result = ServiceWorkLogic::cancelAllocation($params,$this->adminInfo);
  159. if (true === $result) {
  160. return $this->success('操作成功!', [], 1, 1);
  161. }
  162. return $this->fail(ServiceWorkLogic::getError());
  163. }
  164. public function addCustomerLog()
  165. {
  166. $params = (new ServiceWorkValidate())->post()->goCheck('detail',[
  167. 'admin_id' => $this->adminId,
  168. ]);
  169. $result = ServiceWorkLogic::addCustomerLog($params);
  170. if (true === $result) {
  171. return $this->success('操作成功!', [], 1, 1);
  172. }
  173. return $this->fail(ServiceWorkLogic::getError());
  174. }
  175. public function confirmServiceFinish()
  176. {
  177. $params = request()->post();
  178. $params['admin_id'] = $this->adminId;
  179. $result = ServiceOrderLogic::confirmServiceFinish($params);
  180. if (false === $result) {
  181. return $this->fail(ServiceOrderLogic::getError());
  182. }
  183. // 订单完成通知【给用户】 - 全款 -通知
  184. ServiceOrderLogic::serviceFinishNotice($params);
  185. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  186. ServiceOrderLogic::orderQuantityRule($params);
  187. return $this->success('操作成功!', [], 1, 1);
  188. }
  189. }