1
0

ServiceWorkController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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\adminapi\controller\works;
  15. use app\adminapi\controller\BaseAdminController;
  16. use app\adminapi\lists\works\ServiceWorkLists;
  17. use app\adminapi\logic\master_worker\MasterWorkerLogic;
  18. use app\adminapi\logic\works\ServiceWorkLogic;
  19. use app\adminapi\validate\works\ServiceWorkValidate;
  20. /**
  21. * ServiceWork控制器
  22. * Class WorksController
  23. * @package app\adminapi\controller\works
  24. */
  25. class ServiceWorkController extends BaseAdminController
  26. {
  27. /**
  28. * @notes 获取列表
  29. * @return \think\response\Json
  30. * @author likeadmin
  31. * @date 2024/07/10 15:06
  32. */
  33. public function lists()
  34. {
  35. return $this->dataLists(new ServiceWorkLists());
  36. }
  37. /**
  38. * @notes 添加
  39. * @return \think\response\Json
  40. * @author likeadmin
  41. * @date 2024/07/10 15:06
  42. */
  43. public function add()
  44. {
  45. $params = (new ServiceWorkValidate())->post()->goCheck('add');
  46. $result = ServiceWorkLogic::add($params);
  47. if (true === $result) {
  48. return $this->success('添加成功', [], 1, 1);
  49. }
  50. return $this->fail(ServiceWorkLogic::getError());
  51. }
  52. /**
  53. * @notes 编辑
  54. * @return \think\response\Json
  55. * @author likeadmin
  56. * @date 2024/07/10 15:06
  57. */
  58. public function edit()
  59. {
  60. $params = (new ServiceWorkValidate())->post()->goCheck('edit');
  61. $workDetail = ServiceWorkLogic::detail($params);
  62. $result = ServiceWorkLogic::edit($params);
  63. if (true === $result) {
  64. if(strtotime($workDetail['appointment_time']) !== strtotime($params['appointment_time']) && !empty($workDetail['master_worker_id'])){
  65. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  66. // 修改预约时间通知【给用户的通知】
  67. $res = event('Notice', [
  68. 'scene_id' => 117,
  69. 'params' => [
  70. 'user_id' => $workDetail['user_id'],
  71. 'date' => $params['appointment_time'],
  72. 'tel' => $masterDetail['mobile'],
  73. ]
  74. ]);
  75. // 修改预约时间通知【给工程师的通知,仅限公众号】
  76. $res = event('Notice', [
  77. 'scene_id' => 118,
  78. 'params' => [
  79. 'user_id' => $workDetail['master_worker_id'],
  80. 'order_id' => $workDetail['id'],
  81. 'thing4' => $workDetail['title'],
  82. 'time5' => $workDetail['appointment_time'],
  83. 'time6' => $params['appointment_time'],
  84. 'thing11' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  85. 'phone_number8' => $workDetail['mobile'],
  86. ]
  87. ]);
  88. }
  89. return $this->success('编辑成功', [], 1, 1);
  90. }
  91. return $this->fail(ServiceWorkLogic::getError());
  92. }
  93. /**
  94. * @notes 删除
  95. * @return \think\response\Json
  96. * @author likeadmin
  97. * @date 2024/07/10 15:06
  98. */
  99. public function delete()
  100. {
  101. $params = (new ServiceWorkValidate())->post()->goCheck('delete');
  102. $result = ServiceWorkLogic::edit($params);
  103. if (true === $result) {
  104. return $this->success('编辑成功', [], 1, 1);
  105. }
  106. return $this->success('分配成功', [], 1, 1);
  107. }
  108. /**
  109. * @notes 获取详情
  110. * @return \think\response\Json
  111. * @author likeadmin
  112. * @date 2024/07/10 15:06
  113. */
  114. public function detail()
  115. {
  116. $params = (new ServiceWorkValidate())->goCheck('detail');
  117. $result = ServiceWorkLogic::detail($params);
  118. return $this->data($result);
  119. }
  120. public function allocateWorker()
  121. {
  122. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  123. $result = ServiceWorkLogic::allocateWorker($params,$this->adminInfo);
  124. if (true === $result) {
  125. // 工程师派单通知【给工程师的通知】【公众号通知,不发短信】
  126. $workDetail = ServiceWorkLogic::detail($params);
  127. $res = event('Notice', [
  128. 'scene_id' => 113,
  129. 'params' => [
  130. 'user_id' => $params['master_worker_id'],
  131. 'order_id' => $params['id'],
  132. 'thing9' => $workDetail['title'],
  133. 'time7' => $workDetail['appointment_time'],
  134. 'thing8' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  135. 'phone_number6' => $workDetail['mobile'],
  136. ]
  137. ]);
  138. return $this->success('分配工程师成功', [], 1, 1);
  139. }
  140. return $this->fail(ServiceWorkLogic::getError());
  141. }
  142. public function cancelWorker()
  143. {
  144. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  145. $result = ServiceWorkLogic::cancel($params);
  146. if (true === $result) {
  147. return $this->success('取消工单成功!', [], 1, 1);
  148. }
  149. return $this->fail(ServiceWorkLogic::getError());
  150. }
  151. public function settlementMaster()
  152. {
  153. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  154. $result = ServiceWorkLogic::settlement($params);
  155. if (true === $result) {
  156. return $this->success('操作成功!', [], 1, 1);
  157. }
  158. return $this->fail(ServiceWorkLogic::getError());
  159. }
  160. public function notApproved()
  161. {
  162. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  163. $result = ServiceWorkLogic::notApproved($params);
  164. if (true === $result) {
  165. return $this->success('操作成功!', [], 1, 1);
  166. }
  167. return $this->fail(ServiceWorkLogic::getError());
  168. }
  169. public function cancelAllocation()
  170. {
  171. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  172. $result = ServiceWorkLogic::cancelAllocation($params,$this->adminInfo);
  173. if (true === $result) {
  174. return $this->success('操作成功!', [], 1, 1);
  175. }
  176. return $this->fail(ServiceWorkLogic::getError());
  177. }
  178. }