ServiceWorkController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. return $this->success('取消工单成功!', [], 1, 1);
  151. }
  152. return $this->fail(ServiceWorkLogic::getError());
  153. }
  154. public function settlementMaster()
  155. {
  156. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  157. $result = ServiceWorkLogic::settlement($params);
  158. if (true === $result) {
  159. return $this->success('操作成功!', [], 1, 1);
  160. }
  161. return $this->fail(ServiceWorkLogic::getError());
  162. }
  163. public function notApproved()
  164. {
  165. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  166. $result = ServiceWorkLogic::notApproved($params);
  167. if (true === $result) {
  168. return $this->success('操作成功!', [], 1, 1);
  169. }
  170. return $this->fail(ServiceWorkLogic::getError());
  171. }
  172. public function cancelAllocation()
  173. {
  174. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  175. $result = ServiceWorkLogic::cancelAllocation($params,$this->adminInfo);
  176. if (true === $result) {
  177. return $this->success('操作成功!', [], 1, 1);
  178. }
  179. return $this->fail(ServiceWorkLogic::getError());
  180. }
  181. public function addCustomerLog()
  182. {
  183. $params = (new ServiceWorkValidate())->post()->goCheck('detail',[
  184. 'admin_id' => $this->adminId,
  185. ]);
  186. $result = ServiceWorkLogic::addCustomerLog($params);
  187. if (true === $result) {
  188. return $this->success('操作成功!', [], 1, 1);
  189. }
  190. return $this->fail(ServiceWorkLogic::getError());
  191. }
  192. public function confirmServiceFinish()
  193. {
  194. $params = request()->post();
  195. $params['admin_id'] = $this->adminId;
  196. $result = ServiceOrderLogic::confirmServiceFinish($params);
  197. if (false === $result) {
  198. return $this->fail(ServiceOrderLogic::getError());
  199. }
  200. // 订单完成通知【给用户】 - 全款 -通知
  201. ServiceOrderLogic::serviceFinishNotice($params);
  202. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  203. ServiceOrderLogic::orderQuantityRule($params);
  204. return $this->success('操作成功!', [], 1, 1);
  205. }
  206. /**
  207. * 工单分配给租户
  208. * @return \think\response\Json
  209. */
  210. public function distributeTenants()
  211. {
  212. $params = request()->post();
  213. $params['admin_id'] = $this->adminId;
  214. $result = ServiceWorkLogic::distributeTenants($params,$this->adminInfo);
  215. if (true === $result) {
  216. return $this->success('分配成功', [], 1, 1);
  217. }
  218. return $this->fail(ServiceWorkLogic::getError());
  219. }
  220. /**
  221. * 手动添加工单到第三方平台 (暂时只有美团)
  222. * @return \think\response\Json
  223. */
  224. public function addThirdPlatformsOrders()
  225. {
  226. $params = request()->post();
  227. $result = ServiceWorkLogic::addThirdPlatformsOrders($params);
  228. if (false === $result) {
  229. return $this->fail(ServiceWorkLogic::getError());
  230. }
  231. return $this->success('添加成功', [], 1, 1);
  232. }
  233. /**
  234. * 终止服务
  235. */
  236. public function terminateService()
  237. {
  238. $params = request()->post();
  239. $result = ServiceWorkLogic::terminateService($params);
  240. if (false === $result) {
  241. return $this->fail(ServiceWorkLogic::getError());
  242. }
  243. return $this->success('操作成功', [], 1, 1);
  244. }
  245. /**
  246. * 给用户发券
  247. */
  248. public function userAddVoucher()
  249. {
  250. $params = request()->post();
  251. $result = ServiceWorkLogic::userAddVoucher($params);
  252. if (false === $result) {
  253. return $this->fail(ServiceWorkLogic::getError());
  254. }
  255. return $this->success('发券成功', [], 1, 1);
  256. }
  257. /**
  258. * 给用户加单
  259. */
  260. public function userExtendOrder()
  261. {
  262. $params = request()->post();
  263. $result = ServiceWorkLogic::userExtendOrder($params);
  264. if (false === $result) {
  265. return $this->fail(ServiceWorkLogic::getError());
  266. }
  267. return $this->success('加单成功', [], 1, 1);
  268. }
  269. /**
  270. * 代用户上门
  271. */
  272. public function confirmDoor()
  273. {
  274. $params = request()->post(); // work_sn user_id=master_worker_id user_info .worker_number .real_name
  275. $params['user_id'] = $params['master_worker_id'];
  276. $params['user_info']['worker_number'] = $this->adminId;
  277. $params['user_info']['real_name'] = $this->adminInfo['name'];
  278. $result = ServiceWorkLogic::confirmDoor($params);
  279. if (false === $result) {
  280. return $this->fail(ServiceWorkLogic::getError());
  281. }
  282. return $this->success('操作成功', [], 1, 1);
  283. }
  284. public function appointmentLists()
  285. {
  286. return $this->dataLists(new ServiceWorkAppointmentLists());
  287. }
  288. public function appointmentAudit()
  289. {
  290. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  291. $result = ServiceWorkLogic::appointmentAudit($params);
  292. if (false === $result) {
  293. return $this->fail(ServiceWorkLogic::getError());
  294. }
  295. return $this->success('操作成功', [], 1, 1);
  296. }
  297. }