1
0

ServiceWorkController.php 12 KB

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