ServiceWorkController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. use Exception;
  26. /**
  27. * ServiceWork控制器
  28. * Class WorksController
  29. * @package app\adminapi\controller\works
  30. */
  31. class ServiceWorkController extends BaseAdminController
  32. {
  33. /**
  34. * @notes 获取列表
  35. * @return \think\response\Json
  36. * @author likeadmin
  37. * @date 2024/07/10 15:06
  38. */
  39. public function lists()
  40. {
  41. return $this->dataLists(new ServiceWorkLists());
  42. }
  43. /**
  44. * @notes 编辑
  45. * @return \think\response\Json
  46. * @author likeadmin
  47. * @date 2024/07/10 15:06
  48. */
  49. public function edit()
  50. {
  51. $params = (new ServiceWorkValidate())->post()->goCheck('edit');
  52. $workDetail = ServiceWorkLogic::detail($params);
  53. //预约时间修改时,同步更新预计完成时间
  54. if ($workDetail['estimated_finish_time'] && $workDetail['appointment_time'] != $params['appointment_time']) {
  55. $params['estimated_finish_time'] = strtotime($params['appointment_time']) + (strtotime($workDetail['estimated_finish_time']) - strtotime($workDetail['appointment_time']));
  56. } else {
  57. $params['estimated_finish_time'] = strtotime($workDetail['estimated_finish_time']);
  58. }
  59. $result = ServiceWorkLogic::edit($params);
  60. if (true === $result) {
  61. if(strtotime($workDetail['appointment_time']) !== strtotime($params['appointment_time']) && !empty($workDetail['master_worker_id'])){
  62. $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
  63. // 商家改约通知外部平台 即改约
  64. if($workDetail['external_platform_id'] > 0){
  65. event('ExternalPlatform', [
  66. 'send_code' => 1002,
  67. 'params' => [
  68. 'work_id' => $workDetail['id'],
  69. ]
  70. ]);
  71. }
  72. // 修改预约时间通知【给用户的通知】
  73. $res = event('Notice', [
  74. 'scene_id' => 117,
  75. 'params' => [
  76. 'user_id' => $workDetail['user_id'],
  77. 'date' => $params['appointment_time'],
  78. 'tel' => asteriskString($masterDetail['mobile']),
  79. ]
  80. ]);
  81. // 修改预约时间通知【给工程师的通知,仅限公众号】
  82. $res = event('Notice', [
  83. 'scene_id' => 118,
  84. 'params' => [
  85. 'user_id' => $workDetail['master_worker_id'],
  86. 'order_id' => $workDetail['id'],
  87. 'thing4' => $workDetail['title'],
  88. 'time5' => $workDetail['appointment_time'],
  89. 'time6' => $params['appointment_time'],
  90. 'thing11' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
  91. 'phone_number8' => asteriskString($workDetail['mobile']),
  92. ]
  93. ]);
  94. }
  95. return $this->success('编辑成功', [], 1, 1);
  96. }
  97. return $this->fail(ServiceWorkLogic::getError());
  98. }
  99. /**
  100. * @notes 删除
  101. * @return \think\response\Json
  102. * @author likeadmin
  103. * @date 2024/07/10 15:06
  104. */
  105. public function delete()
  106. {
  107. $params = (new ServiceWorkValidate())->post()->goCheck('delete');
  108. $result = ServiceWorkLogic::edit($params);
  109. if (true === $result) {
  110. return $this->success('编辑成功', [], 1, 1);
  111. }
  112. return $this->success('分配成功', [], 1, 1);
  113. }
  114. /**
  115. * @notes 获取详情
  116. * @return \think\response\Json
  117. * @author likeadmin
  118. * @date 2024/07/10 15:06
  119. */
  120. public function detail()
  121. {
  122. $params = (new ServiceWorkValidate())->goCheck('detail');
  123. $result = ServiceWorkLogic::detail($params);
  124. return $this->data($result);
  125. }
  126. public function allocateWorker()
  127. {
  128. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  129. $result = ServiceWorkLogic::allocateWorker($params,$this->adminInfo);
  130. if (true === $result) {
  131. return $this->success('分配工程师成功', [], 1, 1);
  132. }
  133. return $this->fail(ServiceWorkLogic::getError());
  134. }
  135. public function cancelWorker()
  136. {
  137. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  138. $result = ServiceWorkLogic::cancel($params);
  139. if (true === $result) {
  140. UserEquityLogic::cancelServiceWorkRestoredNumber($params);
  141. $serviceWorkInfo = ServiceWork::find($params['id']);
  142. // 商家取消通知外部平台 即取消
  143. if($serviceWorkInfo['external_platform_id'] > 0){
  144. event('ExternalPlatform', [
  145. 'send_code' => 1005,
  146. 'params' => [
  147. 'work_id' => $serviceWorkInfo['id'],
  148. ]
  149. ]);
  150. }
  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. /**
  165. * 配件审核
  166. * @return \think\response\Json
  167. * @author liugc <466014217@qq.com>
  168. * @date 2025/5/9 9:18
  169. */
  170. public function settlementSpare()
  171. {
  172. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  173. $result = ServiceWorkLogic::settlementSpare($params);
  174. if (true === $result) {
  175. return $this->success('操作成功!', [], 1, 1);
  176. }
  177. return $this->fail(ServiceWorkLogic::getError());
  178. }
  179. public function notApproved()
  180. {
  181. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  182. $result = ServiceWorkLogic::notApproved($params);
  183. if (true === $result) {
  184. return $this->success('操作成功!', [], 1, 1);
  185. }
  186. return $this->fail(ServiceWorkLogic::getError());
  187. }
  188. public function cancelAllocation()
  189. {
  190. $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
  191. $result = ServiceWorkLogic::cancelAllocation($params,$this->adminInfo);
  192. if (true === $result) {
  193. return $this->success('操作成功!', [], 1, 1);
  194. }
  195. return $this->fail(ServiceWorkLogic::getError());
  196. }
  197. public function addCustomerLog()
  198. {
  199. $params = (new ServiceWorkValidate())->post()->goCheck('detail',[
  200. 'admin_id' => $this->adminId,
  201. ]);
  202. $result = ServiceWorkLogic::addCustomerLog($params);
  203. if (true === $result) {
  204. return $this->success('操作成功!', [], 1, 1);
  205. }
  206. return $this->fail(ServiceWorkLogic::getError());
  207. }
  208. public function confirmServiceFinish()
  209. {
  210. $params = request()->post();
  211. $params['admin_id'] = $this->adminId;
  212. $result = ServiceOrderLogic::confirmServiceFinish($params);
  213. if (false === $result) {
  214. return $this->fail(ServiceOrderLogic::getError());
  215. }
  216. // 订单完成通知【给用户】 - 全款 -通知
  217. ServiceOrderLogic::serviceFinishNotice($params);
  218. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  219. ServiceOrderLogic::orderQuantityRule($params);
  220. return $this->success('操作成功!', [], 1, 1);
  221. }
  222. /**
  223. * 工单分配给租户
  224. * @return \think\response\Json
  225. */
  226. public function distributeTenants()
  227. {
  228. $params = request()->post();
  229. $params['admin_id'] = $this->adminId;
  230. $result = ServiceWorkLogic::distributeTenants($params,$this->adminInfo);
  231. if (true === $result) {
  232. return $this->success('分配成功', [], 1, 1);
  233. }
  234. return $this->fail(ServiceWorkLogic::getError());
  235. }
  236. /**
  237. * 手动添加工单到第三方平台 (暂时只有美团)
  238. * @return \think\response\Json
  239. */
  240. public function addThirdPlatformsOrders()
  241. {
  242. $params = request()->post();
  243. $result = ServiceWorkLogic::addThirdPlatformsOrders($params);
  244. if (false === $result) {
  245. return $this->fail(ServiceWorkLogic::getError());
  246. }
  247. return $this->success('添加成功', [], 1, 1);
  248. }
  249. /**
  250. * 终止服务
  251. */
  252. public function terminateService()
  253. {
  254. $params = request()->post();
  255. $result = ServiceWorkLogic::terminateService($params);
  256. if (false === $result) {
  257. return $this->fail(ServiceWorkLogic::getError());
  258. }
  259. return $this->success('操作成功', [], 1, 1);
  260. }
  261. /**
  262. * 给用户发券
  263. */
  264. public function userAddVoucher()
  265. {
  266. $params = request()->post();
  267. $result = ServiceWorkLogic::userAddVoucher($params);
  268. if (false === $result) {
  269. return $this->fail(ServiceWorkLogic::getError());
  270. }
  271. return $this->success('发券成功', [], 1, 1);
  272. }
  273. /**
  274. * 给用户加单
  275. */
  276. public function userExtendOrder()
  277. {
  278. $params = request()->post();
  279. $result = ServiceWorkLogic::userExtendOrder($params);
  280. if (false === $result) {
  281. return $this->fail(ServiceWorkLogic::getError());
  282. }
  283. return $this->success('加单成功', [], 1, 1);
  284. }
  285. /**
  286. * 代用户上门
  287. */
  288. public function confirmDoor()
  289. {
  290. $params = request()->post(); // work_sn user_id=master_worker_id user_info .worker_number .real_name
  291. $params['user_id'] = $params['master_worker_id'];
  292. $params['user_info']['worker_number'] = $this->adminId;
  293. $params['user_info']['real_name'] = $this->adminInfo['name'];
  294. $result = ServiceWorkLogic::confirmDoor($params);
  295. if (false === $result) {
  296. return $this->fail(ServiceWorkLogic::getError());
  297. }
  298. return $this->success('操作成功', [], 1, 1);
  299. }
  300. public function appointmentLists()
  301. {
  302. return $this->dataLists(new ServiceWorkAppointmentLists());
  303. }
  304. public function appointmentAudit()
  305. {
  306. $params = (new ServiceWorkValidate())->post()->goCheck('detail');
  307. $result = ServiceWorkLogic::appointmentAudit($params);
  308. if (false === $result) {
  309. return $this->fail(ServiceWorkLogic::getError());
  310. }
  311. return $this->success('操作成功', [], 1, 1);
  312. }
  313. public function shareOrder()
  314. {
  315. $params = request()->post();
  316. $result = ServiceWorkLogic::shareOrderToNative($params);
  317. return $this->success('', $result, 1, 1);
  318. }
  319. public function shareFirstAmountToNative()
  320. {
  321. try {
  322. $params = request()->post();
  323. $result = ServiceWorkLogic::shareFirstAmountToNative($params);
  324. if (false === $result) {
  325. return $this->fail(ServiceWorkLogic::getError());
  326. }
  327. return $this->success('', $result, 1, 1);
  328. } catch (Exception $e) {
  329. return $this->fail($e->getMessage());
  330. }
  331. }
  332. public function shareFixedAmountToNative()
  333. {
  334. try {
  335. $params = request()->post();
  336. $result = ServiceWorkLogic::shareFixedAmountToNative($params);
  337. if (false === $result) {
  338. return $this->fail(ServiceWorkLogic::getError());
  339. }
  340. return $this->success('', $result, 1, 1);
  341. } catch (Exception $e) {
  342. return $this->fail($e->getMessage());
  343. }
  344. }
  345. }