ServiceWorkController.php 7.3 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\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. $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. return $this->success('分配工程师成功', [], 1, 1);
  112. }
  113. return $this->fail(ServiceWorkLogic::getError());
  114. }
  115. public function cancelWorker()
  116. {
  117. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  118. $result = ServiceWorkLogic::cancel($params);
  119. if (true === $result) {
  120. return $this->success('取消工单成功!', [], 1, 1);
  121. }
  122. return $this->fail(ServiceWorkLogic::getError());
  123. }
  124. public function settlementMaster()
  125. {
  126. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  127. $result = ServiceWorkLogic::settlement($params);
  128. if (true === $result) {
  129. return $this->success('操作成功!', [], 1, 1);
  130. }
  131. return $this->fail(ServiceWorkLogic::getError());
  132. }
  133. public function notApproved()
  134. {
  135. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  136. $result = ServiceWorkLogic::notApproved($params);
  137. if (true === $result) {
  138. return $this->success('操作成功!', [], 1, 1);
  139. }
  140. return $this->fail(ServiceWorkLogic::getError());
  141. }
  142. public function cancelAllocation()
  143. {
  144. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  145. $result = ServiceWorkLogic::cancelAllocation($params,$this->adminInfo);
  146. if (true === $result) {
  147. return $this->success('操作成功!', [], 1, 1);
  148. }
  149. return $this->fail(ServiceWorkLogic::getError());
  150. }
  151. public function addCustomerLog()
  152. {
  153. $params = (new ServiceWorkValidate())->post()->goCheck('detail',[
  154. 'admin_id' => $this->adminId,
  155. ]);
  156. $result = ServiceWorkLogic::addCustomerLog($params);
  157. if (true === $result) {
  158. return $this->success('操作成功!', [], 1, 1);
  159. }
  160. return $this->fail(ServiceWorkLogic::getError());
  161. }
  162. public function confirmServiceFinish()
  163. {
  164. $params = request()->post();
  165. $params['admin_id'] = $this->adminId;
  166. $result = ServiceOrderLogic::confirmServiceFinish($params);
  167. if (false === $result) {
  168. return $this->fail(ServiceOrderLogic::getError());
  169. }
  170. // 订单完成通知【给用户】 - 全款 -通知
  171. ServiceOrderLogic::serviceFinishNotice($params);
  172. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  173. ServiceOrderLogic::orderQuantityRule($params);
  174. return $this->success('操作成功!', [], 1, 1);
  175. }
  176. public function distributeTenants()
  177. {
  178. $params = request()->post();
  179. $params['admin_id'] = $this->adminId;
  180. $result = ServiceWorkLogic::distributeTenants($params);
  181. if (true === $result) {
  182. return $this->success('分配成功', [], 1, 1);
  183. }
  184. return $this->fail(ServiceWorkLogic::getError());
  185. }
  186. }