ServiceWorkController.php 8.6 KB

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