ServiceWorkController.php 10 KB

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