1
0

ServiceWorkController.php 8.4 KB

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