ServiceWorkController.php 9.9 KB

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