ServiceWorkController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. use app\api\logic\ServiceOrderLogic;
  21. /**
  22. * ServiceWork控制器
  23. * Class WorksController
  24. * @package app\adminapi\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. //预约时间修改时,同步更新预计完成时间
  49. if ($workDetail['estimated_finish_time'] && $workDetail['appointment_time'] != $params['appointment_time']) {
  50. $params['estimated_finish_time'] = strtotime($params['appointment_time']) + (strtotime($workDetail['estimated_finish_time']) - strtotime($workDetail['appointment_time']));
  51. } else {
  52. $params['estimated_finish_time'] = strtotime($workDetail['estimated_finish_time']);
  53. }
  54. $result = ServiceWorkLogic::edit($params);
  55. if (true === $result) {
  56. if(strtotime($workDetail['appointment_time']) !== strtotime($params['appointment_time']) && !empty($workDetail['master_worker_id'])){
  57. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  58. // 修改预约时间通知【给用户的通知】
  59. $res = event('Notice', [
  60. 'scene_id' => 117,
  61. 'params' => [
  62. 'user_id' => $workDetail['user_id'],
  63. 'date' => $params['appointment_time'],
  64. 'tel' => asteriskString($masterDetail['mobile']),
  65. ]
  66. ]);
  67. // 修改预约时间通知【给工程师的通知,仅限公众号】
  68. $res = event('Notice', [
  69. 'scene_id' => 118,
  70. 'params' => [
  71. 'user_id' => $workDetail['master_worker_id'],
  72. 'order_id' => $workDetail['id'],
  73. 'thing4' => $workDetail['title'],
  74. 'time5' => $workDetail['appointment_time'],
  75. 'time6' => $params['appointment_time'],
  76. 'thing11' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  77. 'phone_number8' => asteriskString($workDetail['mobile']),
  78. ]
  79. ]);
  80. }
  81. return $this->success('编辑成功', [], 1, 1);
  82. }
  83. return $this->fail(ServiceWorkLogic::getError());
  84. }
  85. /**
  86. * @notes 删除
  87. * @return \think\response\Json
  88. * @author likeadmin
  89. * @date 2024/07/10 15:06
  90. */
  91. public function delete()
  92. {
  93. $params = (new ServiceWorkValidate())->post()->goCheck('delete');
  94. $result = ServiceWorkLogic::edit($params);
  95. if (true === $result) {
  96. return $this->success('编辑成功', [], 1, 1);
  97. }
  98. return $this->success('分配成功', [], 1, 1);
  99. }
  100. /**
  101. * @notes 获取详情
  102. * @return \think\response\Json
  103. * @author likeadmin
  104. * @date 2024/07/10 15:06
  105. */
  106. public function detail()
  107. {
  108. $params = (new ServiceWorkValidate())->goCheck('detail');
  109. $result = ServiceWorkLogic::detail($params);
  110. return $this->data($result);
  111. }
  112. public function allocateWorker()
  113. {
  114. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  115. $result = ServiceWorkLogic::allocateWorker($params,$this->adminInfo);
  116. if (true === $result) {
  117. return $this->success('分配工程师成功', [], 1, 1);
  118. }
  119. return $this->fail(ServiceWorkLogic::getError());
  120. }
  121. public function cancelWorker()
  122. {
  123. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  124. $result = ServiceWorkLogic::cancel($params);
  125. if (true === $result) {
  126. return $this->success('取消工单成功!', [], 1, 1);
  127. }
  128. return $this->fail(ServiceWorkLogic::getError());
  129. }
  130. public function settlementMaster()
  131. {
  132. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  133. $result = ServiceWorkLogic::settlement($params);
  134. if (true === $result) {
  135. return $this->success('操作成功!', [], 1, 1);
  136. }
  137. return $this->fail(ServiceWorkLogic::getError());
  138. }
  139. public function notApproved()
  140. {
  141. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  142. $result = ServiceWorkLogic::notApproved($params);
  143. if (true === $result) {
  144. return $this->success('操作成功!', [], 1, 1);
  145. }
  146. return $this->fail(ServiceWorkLogic::getError());
  147. }
  148. public function cancelAllocation()
  149. {
  150. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  151. $result = ServiceWorkLogic::cancelAllocation($params,$this->adminInfo);
  152. if (true === $result) {
  153. return $this->success('操作成功!', [], 1, 1);
  154. }
  155. return $this->fail(ServiceWorkLogic::getError());
  156. }
  157. public function addCustomerLog()
  158. {
  159. $params = (new ServiceWorkValidate())->post()->goCheck('detail',[
  160. 'admin_id' => $this->adminId,
  161. ]);
  162. $result = ServiceWorkLogic::addCustomerLog($params);
  163. if (true === $result) {
  164. return $this->success('操作成功!', [], 1, 1);
  165. }
  166. return $this->fail(ServiceWorkLogic::getError());
  167. }
  168. public function confirmServiceFinish()
  169. {
  170. $params = request()->post();
  171. $params['admin_id'] = $this->adminId;
  172. $result = ServiceOrderLogic::confirmServiceFinish($params);
  173. if (false === $result) {
  174. return $this->fail(ServiceOrderLogic::getError());
  175. }
  176. // 订单完成通知【给用户】 - 全款 -通知
  177. ServiceOrderLogic::serviceFinishNotice($params);
  178. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  179. ServiceOrderLogic::orderQuantityRule($params);
  180. return $this->success('操作成功!', [], 1, 1);
  181. }
  182. public function distributeTenants()
  183. {
  184. $params = request()->post();
  185. $params['admin_id'] = $this->adminId;
  186. $result = ServiceWorkLogic::distributeTenants($params);
  187. if (true === $result) {
  188. return $this->success('分配成功', [], 1, 1);
  189. }
  190. return $this->fail(ServiceWorkLogic::getError());
  191. }
  192. }