ServiceWorkController.php 9.8 KB

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