UserJsController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-12
  6. * Time: 14:26
  7. */
  8. namespace api\js\controller;
  9. use Aliyun\DySDKLite\SignatureHelper;
  10. use api\js\model\DistributorLogModel;
  11. use api\js\model\DistributorModel;
  12. use api\js\model\JsCallModel;
  13. use api\js\model\JsCourseOrderModel;
  14. use api\js\model\JsModel;
  15. use api\js\model\JsOrderGrabModel;
  16. use api\js\model\JsOrderModel;
  17. use api\js\model\JsProjectCategoryModel;
  18. use api\js\model\JsProjectModel;
  19. use api\js\model\JsTimeModel;
  20. use api\js\model\UserModel;
  21. use cmf\controller\RestUserBaseController;
  22. use JPush\Client;
  23. use think\Db;
  24. class UserJsController extends RestUserBaseController
  25. {
  26. protected $js_id;
  27. protected $js_status = false;
  28. public function initialize()
  29. {
  30. $user_id = $this->getUserId();
  31. $JsModel = new JsModel();
  32. $js_info = $JsModel::where('user_id', $user_id)->find();
  33. if ($js_info['id']) {
  34. $this->js_id = $js_info['id'];
  35. if ($js_info['js_status'] == 1) {
  36. $this->js_status = true;
  37. }
  38. }
  39. parent::initialize(); // TODO: Change the autogenerated stub
  40. }
  41. /**
  42. * 注销技师账户
  43. *
  44. * @param [type] $mobile
  45. * @param [type] $product
  46. * @return void
  47. */
  48. public function destroy()
  49. {
  50. $info = JsModel::get($this->js_id);
  51. $res = $info->delete();
  52. $this->success('注销成功', $res);
  53. }
  54. /**
  55. * 向用户发送短信通知
  56. *
  57. * @param [type] $mobile
  58. * @param [type] $product
  59. * @return void
  60. */
  61. protected function sendMsg($mobile, $product)
  62. {
  63. $helper = new SignatureHelper();
  64. $alisms = cmf_get_option('alisms');
  65. $security = false;
  66. $accessKeyId = $alisms['access_key_id'];
  67. $accessKeySecret = $alisms['access_key_secret'];
  68. $js_mobile = $mobile;
  69. $params["PhoneNumbers"] = $js_mobile;
  70. $params["SignName"] = '嘀咚点到';
  71. $params["TemplateCode"] = 'SMS_247620502';
  72. $params['TemplateParam'] = array(
  73. "product" => $product,
  74. );
  75. if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  76. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  77. }
  78. $content = $helper->request(
  79. $accessKeyId,
  80. $accessKeySecret,
  81. "dysmsapi.aliyuncs.com",
  82. array_merge($params, array(
  83. "RegionId" => "cn-hangzhou",
  84. "Action" => "SendSms",
  85. "Version" => "2017-05-25",
  86. )),
  87. $security
  88. );
  89. }
  90. /**
  91. * 技师用户个人中心
  92. */
  93. public function getInfo()
  94. {
  95. if (!$this->js_id) {
  96. $this->error('认证信息不存在!');
  97. }
  98. $info = JsModel::get($this->js_id);
  99. $info->score = get_js_score($this->js_id);
  100. $info->distributor_status = DistributorLogModel::where('user_id', $this->userId)->value('chuli_status');
  101. $info->fenxiaoshang = DistributorModel::get(UserModel::get($this->userId)['agency_id'])['name'];
  102. $info = $info->toarray();
  103. $info['js']['name'] = $info['name'];
  104. $info['js']['avatar'] = $info['avatar'];
  105. $this->success('ok', $info);
  106. }
  107. /**
  108. * 加载我的时间
  109. */
  110. public function getTime()
  111. {
  112. $user_id = $this->getUserId();
  113. $JsModel = new JsModel();
  114. $jsId = $JsModel::where('user_id', $user_id)->value('id');
  115. $JsTimeModel = new JsTimeModel();
  116. $list = $JsTimeModel::where('js_id', $jsId)->select();
  117. $this->success('ok', $list);
  118. }
  119. /**
  120. * 添加我的时间
  121. */
  122. public function addTimePost()
  123. {
  124. $user_id = $this->getUserId();
  125. $JsModel = new JsModel();
  126. $data['js_id'] = $JsModel::where('user_id', $user_id)->value('id');
  127. $data['times'] = $this->request->param('times/a');
  128. $data['weeks'] = $this->request->param('week/a');
  129. Db::name('js_time')->where('js_id', $data['js_id'])->delete();
  130. $JsTimeModel = new JsTimeModel();
  131. $JsTimeModel->allowField(true)->isUpdate(false)->save($data);
  132. $this->success('添加成功');
  133. }
  134. /**
  135. * 更改上下钟
  136. * @return void
  137. */
  138. public function setWorkTime()
  139. {
  140. $user_id = $this->getUserId();
  141. $is_work = $this->request->post('is_work');
  142. $data['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
  143. $data['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
  144. if (!$is_work) $data['times'] = [];
  145. $JsModel = new JsModel();
  146. $js_id = $JsModel::where('user_id', $user_id)->value('id');
  147. $JsTimeModel = new JsTimeModel();
  148. $ret = $JsTimeModel->allowField(true)->isUpdate(true)->save($data, ['js_id' => $js_id]);
  149. $this->success($is_work ? '上钟成功' : '下钟成功', $ret);
  150. }
  151. /**
  152. * 获取技师地点
  153. * @throws \think\Exception
  154. * @throws \think\exception\PDOException
  155. */
  156. public function getPostSite()
  157. {
  158. $user_id = $this->getUserId();
  159. $JsModel = new JsModel();
  160. $jsId = $JsModel::where('user_id', $user_id)->value('id');
  161. $res = '';
  162. if ($jsId) {
  163. $id = Db::name('js_site')->where('js_id', $jsId)->value('id');
  164. $res = Db::name('js_site')->where('id', $id)->find();
  165. }
  166. $this->success('ok', $res);
  167. }
  168. /**
  169. * 更新技师地点
  170. * @throws \think\Exception
  171. * @throws \think\exception\PDOException
  172. */
  173. public function addPostSite()
  174. {
  175. $user_id = $this->getUserId();
  176. $JsModel = new JsModel();
  177. $jsId = $JsModel::where('user_id', $user_id)->value('id');
  178. $lng = $this->request->param('long');
  179. $lat = $this->request->param('lat');
  180. $id = 0;
  181. $ret = 0;
  182. if ($jsId) {
  183. $id = Db::name('js_site')->where('js_id', $jsId)->value('id');
  184. if ($id) {
  185. $ret = Db::name('js_site')->where('id', $id)->update(['lng' => $lng, 'lat' => $lat]);
  186. } else {
  187. $ret = Db::name('js_site')->where('id', $id)->insert(['lng' => $lng, 'lat' => $lat, 'js_id' => $jsId]);
  188. }
  189. }
  190. $this->success('定位成功', $ret);
  191. }
  192. /**
  193. * 技师申请项目
  194. */
  195. public function postProject()
  196. {
  197. if (!$this->js_status) {
  198. $this->error('您还没有认证技师!');
  199. }
  200. $data['js_id'] = $this->js_id;
  201. $data['project_id'] = $this->request->param('project_id');
  202. $info = Db::name('js_project_relevancy')->where($data)->field('id,status')->find();
  203. if ($info) {
  204. if ($info['status'] == 0) {
  205. $this->error('您已申请该项目!');
  206. } elseif ($info['status'] == 2) {
  207. $data['add_time'] = time();
  208. Db::name('js_project_relevancy')->update(['status' => 0, 'id' => $info['id']]);
  209. $this->success('申请成功');
  210. }
  211. } else {
  212. $data['add_time'] = time();
  213. Db::name('js_project_relevancy')->insert($data);
  214. $this->success('申请成功');
  215. }
  216. }
  217. /**
  218. * 技师编辑个人信息
  219. */
  220. public function editInfo()
  221. {
  222. $js_id = $this->js_id;
  223. $UserModel = new UserModel();
  224. $mobile = $UserModel->where('id', $this->getUserId())->value('mobile');
  225. // if (!$this->js_status) {
  226. // $this->error('认证暂未通过不可修改!');
  227. // }
  228. $JsModel = new JsModel();
  229. $serviceData = $JsModel->where('id', $js_id)->find();
  230. $data['avatar'] = $this->request->param('avatar');
  231. $data['name'] = $this->request->param('name');
  232. $data['is_make'] = $this->request->param('is_make');
  233. $data['is_real_time'] = $this->request->param('is_real_time');
  234. $data['phone'] = $this->request->param('phone');
  235. $data['phone'] = $data['phone'] ?: $mobile;
  236. $data['jianjie'] = $this->request->param('jianjie');
  237. $sex = $this->request->param('sex');
  238. if (isset($sex)) $data['sex'] = $sex;
  239. if ($serviceData['avatar'] != $data['avatar'] || $serviceData['name'] != $data['name'] || $serviceData['jianjie'] != $data['jianjie'])
  240. $data['js_status'] = 0;
  241. UserModel::where('id', $this->getUserId())->update(['avatar' => $data['avatar']]);
  242. $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $js_id]);
  243. $this->success('修改成功');
  244. }
  245. public function editPicture()
  246. {
  247. $js_id = $this->js_id;
  248. if (!$js_id) {
  249. $this->error('您还没有认证技师!');
  250. }
  251. $data['work'] = $this->request->param('work/a');
  252. // $data['massage'] = $this->request->param('massage/a');
  253. $data['pictures'] = $this->request->param('pictures/a');
  254. $data['js_status'] = 0;
  255. $JsModel = new JsModel();
  256. $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $js_id]);
  257. $this->success('修改成功');
  258. }
  259. public function getPicture()
  260. {
  261. $JsModel = new JsModel();
  262. $info = $JsModel::get($this->js_id);
  263. $res['work'] = $info->work;
  264. $res['pictures'] = $info->pictures;
  265. $this->success('ok', $res);
  266. }
  267. /**
  268. * 视频课程列表
  269. */
  270. public function getCourseList()
  271. {
  272. $name = $this->request->param('name');
  273. $page = $this->request->param('page', 1);
  274. $JsProjectModel = new JsProjectModel();
  275. $jsCourseModel = new JsCourseOrderModel();
  276. $list = $JsProjectModel::with('tag')->where(function ($query) use ($name) {
  277. if ($name) {
  278. $query->where('name', 'like', '%' . $name . '%');
  279. }
  280. })->field('id,name,brief,course_price,video_sl,video')->order('list_order', 'asc')->page($page, 20)->select()->each(function ($list) use ($jsCourseModel) {
  281. $list->video = cmf_get_image_preview_url($list->video);
  282. $list->video_sl = cmf_get_image_preview_url($list->video_sl);
  283. $course_order_status = $jsCourseModel::where(['user_id' => $this->getUserId(), 'project_id' => $list->id])->value('status');
  284. $list->purchase = isset($course_order_status) ? $course_order_status : 0;
  285. });
  286. $this->success('ok', $list);
  287. }
  288. /**
  289. *获取详情
  290. */
  291. public function getCourseInfo()
  292. {
  293. $id = $this->request->param('project_id');
  294. $jsCourseModel = new JsCourseOrderModel();
  295. $course_order_status = $jsCourseModel::where(['user_id' => $this->getUserId(), 'project_id' => $id])->value('status');
  296. $JsProjectModel = new JsProjectModel();
  297. $info = $JsProjectModel::where('id', $id)->field('id,try_minute,video,course_price')->find();
  298. $info->purchase = isset($course_order_status) ? $course_order_status : 0;
  299. $info->video = cmf_get_image_preview_url($info->video);
  300. $this->success('ok', $info);
  301. }
  302. /**
  303. * 创建订单
  304. */
  305. public function addCourseOrder()
  306. {
  307. $id = $this->request->param('project_id');
  308. $pay_price = $this->request->param('pay_price');
  309. $jsCourseModel = new JsCourseOrderModel();
  310. $data['project_id'] = $id;
  311. $data['pay_price'] = $pay_price;
  312. $data['order_sn'] = cmf_get_order_sn();
  313. $data['user_id'] = $this->getUserId();
  314. $jsCourseModel->allowField(true)->isUpdate(false)->save($data);
  315. $this->success('创建订单成功', $jsCourseModel->id);
  316. }
  317. /**
  318. * 支付订单
  319. */
  320. public function pay()
  321. {
  322. $id = $this->request->param('order_id');
  323. $pay_type = $this->request->param('pay_type'); // 1视频支付 2 上传支付
  324. switch ($pay_type) {
  325. case 'alipay';
  326. $res = aly_pay($id, 1);
  327. if (!empty($res['return_code'])) {
  328. $this->error($res['return_msg']);
  329. } else {
  330. $this->success('ok', $res);
  331. }
  332. break;
  333. case 'wxpay';
  334. $res = wx_pay($id, 1);
  335. if (!empty($res['return_code'])) {
  336. $this->error($res['return_msg']);
  337. } else {
  338. $this->success('ok', $res);
  339. }
  340. break;
  341. case 'balance';
  342. $bool = balance_pay($id, 1);
  343. if ($bool === true) {
  344. $this->success('支付成功');
  345. } else {
  346. $this->error($bool);
  347. }
  348. break;
  349. }
  350. }
  351. /**
  352. * 技师服务接单列表
  353. */
  354. public function getProjectOrderList()
  355. {
  356. $js_id = $this->js_id;
  357. if (!$js_id) {
  358. $this->error('您还没有认证技师!');
  359. }
  360. $type = $this->request->param('type', 1);
  361. $page = $this->request->param('page', 1);
  362. $category_id = $this->request->param('category_id');
  363. $js_order_ids = get_js_order_ids($js_id, $type, $page, $category_id, false);
  364. $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
  365. $JsOrderModel = new JsOrderModel();
  366. $list = $JsOrderModel::with('project.tag')->where('id', 'in', $js_order_ids)
  367. ->order('id', 'desc')->select()->each(function ($list) use ($js_site_info) {
  368. $list->project->icon = cmf_get_image_preview_url($list->project->icon);
  369. $list->project->service = Db::name('js_project_service_relevancy')->where('id', $list['service_id'])->find();
  370. $list['distance'] = GetDistance($js_site_info['lat'], $js_site_info['lng'], $list['lat'], $list['lng'], 2, 2);;
  371. return $list;
  372. });
  373. $this->success('ok', $list);
  374. }
  375. /**
  376. * 技师服务抢单列表
  377. */
  378. public function getFastOrderList()
  379. {
  380. $js_id = $this->js_id;
  381. if (!$js_id) {
  382. $this->error('您还没有认证技师!');
  383. }
  384. $type = $this->request->param('type', 1);
  385. $page = $this->request->param('page', 1);
  386. $category_id = $this->request->param('category_id');
  387. $js_order_ids = get_js_order_ids($js_id, $type, $page, $category_id);
  388. $distance = cmf_get_option('distance')['distance'];
  389. $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
  390. $offset = $distance / 111;
  391. $lng_offset = [$js_site_info['lng'] - $offset, $js_site_info['lng'] + $offset];
  392. $lat_offset = [$js_site_info['lat'] - $offset, $js_site_info['lat'] + $offset];
  393. $JsOrderModel = new JsOrderModel();
  394. $list = $JsOrderModel::with('project.tag')->where('id', 'in', $js_order_ids)
  395. ->whereBetween('lat', $lat_offset)
  396. ->whereBetween('lng', $lng_offset)
  397. ->order('id', 'desc')->select()->each(function ($list) use ($js_site_info) {
  398. $list->project->icon = cmf_get_image_preview_url($list->project->icon);
  399. $list->project->service = Db::name('js_project_service_relevancy')->where('id', $list['service_id'])->find();
  400. $list['distance'] = GetDistance($js_site_info['lat'], $js_site_info['lng'], $list['lat'], $list['lng'], 2, 2);;
  401. return $list;
  402. });
  403. $this->success('ok', $list);
  404. }
  405. /**
  406. * 技师屏蔽订单操作
  407. */
  408. public function addShield()
  409. {
  410. $id = $this->request->param('order_id');
  411. if (!$this->js_id) {
  412. $this->error('您没有认证技师!');
  413. }
  414. Db::name('js_shield_log')->insert(['order_id' => $id, 'js_id' => $this->js_id]);
  415. $this->success('操作成功');
  416. }
  417. // /**
  418. // * 技师抢单列表
  419. // */
  420. // public function jsOrderList()
  421. // {
  422. //
  423. // $JsOrderModel = new JsOrderModel();
  424. // $page = $this->request->param('page');
  425. // $js_order_ids = get_js_order_ids($this->js_id,1,$page);
  426. //
  427. // $list = $JsOrderModel::with('project')->where('id','in',$js_order_ids)->select()->each(function ($list){
  428. // $list->project->service = Db::name('js_project_service_relevancy')->where('id',$list['service_id'])->find();
  429. // return $list;
  430. // });
  431. // $this->success('ok',$list);
  432. //
  433. // }
  434. /**
  435. * 技师接单操作
  436. */
  437. public function jeidanPost()
  438. {
  439. $id = $this->request->param('order_id');
  440. $js_id = $this->js_id;
  441. if (!$this->js_status) {
  442. $this->error('您技师认证暂未通过,不可抢单!');
  443. }
  444. $JsOrderGrab = new JsOrderGrabModel();
  445. $JsOrderModel = new JsOrderModel();
  446. $js_order_id = $JsOrderModel::where('jiedan_js_id', $js_id)->where('status', 6)->value('id');
  447. if ($js_order_id) {
  448. $this->error('您有订单未完成,请合理安排时间');
  449. }
  450. $msg = '订单未支付!';
  451. $info = $JsOrderGrab::where(['order_id' => $id, 'js_id' => $js_id])->find();
  452. if ($info) {
  453. $msg = '您已报名参加抢单!';
  454. $this->error($msg);
  455. }
  456. $order_info = $JsOrderModel::get($id);
  457. switch ($order_info['status']) {
  458. case 2:
  459. $msg = '订单已被抢!';
  460. break;
  461. case 6:
  462. $msg = '服务中!';
  463. break;
  464. case 3:
  465. $msg = '订单已完成!';
  466. break;
  467. case 4:
  468. $msg = '订单已评价!';
  469. break;
  470. case 5:
  471. $msg = '订单已取消!';
  472. break;
  473. }
  474. if ($order_info['status'] != 1) {
  475. $this->error($msg);
  476. } else {
  477. if ($order_info['status'] == 1 && $order_info['jiedan_js_id']) {
  478. $result = $JsOrderModel->allowField(true)->isUpdate(true)->save(['jiedan_time' => time(), 'status' => 2], ['id' => $order_info['id']]);
  479. if ($result) {
  480. $mobile = $order_info->mobile;
  481. $order_sn = $order_info->order_sn;
  482. $this->sendMsg($mobile, $order_sn);
  483. }
  484. $this->success('接单成功');
  485. } else {
  486. $JsOrderGrab->allowField(true)->isUpdate(false)->save(['js_id' => $js_id, 'order_id' => $id]);
  487. $this->success('抢单报名成功,等待客户选择');
  488. }
  489. }
  490. }
  491. /**
  492. * 获取抢单数量
  493. */
  494. public function getJsOrdernum()
  495. {
  496. $js_id = $this->js_id;
  497. if (!$this->js_status) {
  498. $this->error('您还没有认证技师!');
  499. }
  500. $category_id = $this->request->param('category_id');
  501. $project_new_ids = [];
  502. $js_project_relevancy_where['js_id'] = $js_id;
  503. $js_project_relevancy_where['status'] = 1;
  504. if ($category_id) {
  505. $project_ids1 = Db::name('js_project_category_relevancy')->where('category_id', $category_id)->field('project_id')->select();
  506. $project_ids2 = [];
  507. foreach ($project_ids1 as $vo) {
  508. $project_ids2[] = $vo['project_id'];
  509. }
  510. $js_project_relevancy_where['project_id'] = $project_ids2;
  511. }
  512. $project_ids = Db::name('js_project_relevancy')->where($js_project_relevancy_where)->field('project_id')->select();
  513. $order_new_ids = [];
  514. $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
  515. foreach ($order_ids as $vo) {
  516. $order_new_ids[] = $vo['order_id'];
  517. }
  518. foreach ($project_ids as $vo) {
  519. $project_new_ids[] = $vo['project_id'];
  520. }
  521. $distance = cmf_get_option('distance')['distance'];
  522. $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
  523. $offset = $distance / 111;
  524. $lng_offset = [$js_site_info['lng'] - $offset, $js_site_info['lng'] + $offset];
  525. $lat_offset = [$js_site_info['lat'] - $offset, $js_site_info['lat'] + $offset];
  526. $JsOrderModel = new JsOrderModel();
  527. $order_coun = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => 0, 'status' => 1])
  528. ->where('id', 'not in', $order_new_ids)
  529. ->whereBetween('lat', $lat_offset)
  530. ->whereBetween('lng', $lng_offset)
  531. ->field('id,lat,lng')->count('id');
  532. $this->success('ok', $order_coun);
  533. }
  534. /**
  535. * 获取接单数量
  536. */
  537. public function getOrdernum()
  538. {
  539. $js_id = $this->js_id;
  540. if (!$this->js_status) {
  541. $this->error('您还没有认证技师!');
  542. }
  543. $order_refuse_ids = [];
  544. $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
  545. foreach ($order_ids as $vo) {
  546. $order_refuse_ids[] = $vo['order_id'];
  547. }
  548. $JsOrderModel = new JsOrderModel();
  549. $order_coun = $JsOrderModel->where(['jiedan_js_id' => $js_id])->where('status', [['eq', 1], ['eq', 2]], 'or')->where('id', 'not in', $order_refuse_ids)->count();
  550. $this->success('ok', $order_coun);
  551. }
  552. /**
  553. * 技师开始服务
  554. */
  555. public function start()
  556. {
  557. $id = $this->request->param('order_id');
  558. $JsOrderModel = new JsOrderModel();
  559. $order_info = $JsOrderModel::where('order_sole', $id)->find();
  560. if (!$order_info) {
  561. $this->error('订单不存在!');
  562. }
  563. $js_id = $this->js_id;
  564. if ($order_info['jiedan_js_id'] != $js_id) {
  565. $this->error('接单人不是您,不可操作!');
  566. }
  567. if ($order_info['status'] != 2) {
  568. $this->error('订单异常');
  569. } else {
  570. $JsOrderModel->allowField(true)->isUpdate(true)->save(['start_time' => time(), 'status' => 6], ['id' => $order_info['id']]);
  571. $this->success('开始服务');
  572. }
  573. }
  574. /**
  575. * 新增地址
  576. */
  577. public function addressPost()
  578. {
  579. $data['user_id'] = $this->getUserId();
  580. $data['province'] = $this->request->param('province');
  581. $data['city'] = $this->request->param('city');
  582. $data['district'] = $this->request->param('district');
  583. $data['address'] = $this->request->param('address');
  584. $data['moren'] = $this->request->param('moren');
  585. $data['name'] = $this->request->param('name');
  586. $data['mobile'] = $this->request->param('mobile');
  587. $id = $this->request->param('id');
  588. if ($id) {
  589. if ($data['moren'] == 1) {
  590. Db::name('user_address')->where('user_id', $data['user_id'])->update(['moren' => 2]);
  591. }
  592. Db::name('user_address')->where('id', $id)->update($data);
  593. } else {
  594. if ($data['moren'] == 1) {
  595. Db::name('user_address')->where('user_id', $data['user_id'])->update(['moren' => 2]);
  596. }
  597. Db::name('user_address')->insert($data);
  598. }
  599. // $address_id = Db::name('user_address')->where(['user_id'=>$data['user_id'],'moren' =>1])->value('id');
  600. // if(!$address_id){
  601. // $data['moren'] = 1;
  602. // }
  603. $this->success('操作成功');
  604. }
  605. public function getaddresslist()
  606. {
  607. $user_id = $this->getUserId();
  608. $list = Db::name('user_address')->where('user_id', $user_id)->select();
  609. $this->success('ok', $list);
  610. }
  611. public function getaddressinfo()
  612. {
  613. $id = $this->request->param('id');
  614. $info = Db::name('user_address')->where('id', $id)->find();
  615. $this->success('ok', $info);
  616. }
  617. public function addressDelete()
  618. {
  619. $id = $this->request->param('id');
  620. Db::name('user_address')->where('id', $id)->delete();
  621. $this->success('删除成功');
  622. }
  623. /**
  624. * 技师报警
  625. */
  626. public function callPost()
  627. {
  628. $js_id = $this->js_id;
  629. if (!$this->js_status) {
  630. $this->error('您还没有认证技师!');
  631. }
  632. $order_id = JsOrderModel::where('jiedan_js_id', $js_id)->where(function ($query) {
  633. $query->where('status', 2);
  634. $query->whereor('status', 6);
  635. })->value('id');
  636. if ($order_id) {
  637. $order_sn = JsOrderModel::where('id', $order_id)->value('order_sn');
  638. }
  639. if (!$order_id) {
  640. $order_id = JsOrderModel::where(['jiedan_js_id' => $js_id, 'status' => 3])->order('finish_time', 'desc')->value('id');
  641. $order_sn = JsOrderModel::where('id', $order_id)->value('order_sn');
  642. $finish_time = JsOrderModel::where(['jiedan_js_id' => $js_id, 'status' => 3, 'id' => $order_id])->value('finish_time');
  643. $alarm_delay = $duration = cmf_get_option('duration')['alarm_delay'];
  644. if (($finish_time + $alarm_delay * 60) < time()) {
  645. $this->error('警报发送失败,没有服务中订单!');
  646. }
  647. }
  648. if (!$order_id) {
  649. $this->error('警报发送失败,没有服务中订单!');
  650. }
  651. $data['user_id'] = $this->getUserId();
  652. $data['order_id'] = $order_id;
  653. $UserModel = new UserModel();
  654. $user_city_id = $UserModel::get($this->getUserId())['city_id'];
  655. $user_district_id = $UserModel::get($this->getUserId())['district_id'];
  656. $city_agency_id = Db::name('agency')->where(['city_id' => $user_city_id, 'renk_id' => 1])->value('id');
  657. $district_agency_id = Db::name('agency')->where(['district_id' => $user_district_id, 'renk_id' => 2])->value('id');
  658. $JsCallModel = new JsCallModel();
  659. $info = cmf_get_option('jspus');
  660. $city_agency_user = $UserModel::where('agency_id', $city_agency_id)->field('id,user_type')->find();
  661. $client = new Client($info['app_key'], $info['master_secret']);
  662. if ($city_agency_user) {
  663. if ($city_agency_user['user_type'] == 3) {
  664. $client = new Client($info['js_app_key'], $info['js_master_secret']);
  665. }
  666. $extras = [
  667. 'id' => $this->getUserId(),
  668. 'flag' => '技师报警',
  669. ];
  670. $array = [
  671. 'extras' => $extras,
  672. ];
  673. $alias = $city_agency_user['id'] . 'js';
  674. $text = '订单号:' . $order_sn . '报警';
  675. $platform = array('ios', 'android');
  676. $client->push()
  677. ->setPlatform($platform)
  678. ->setNotificationAlert($text)
  679. ->iosNotification($text, $array)
  680. ->androidNotification($text, $array)
  681. ->addAlias("{$alias}")
  682. ->send();
  683. }
  684. $district_agency_user = $UserModel::where('agency_id', $district_agency_id)->field('id,user_type')->find();
  685. if ($district_agency_user) {
  686. if ($city_agency_user['user_type'] == 3) {
  687. $client = new Client($info['js_app_key'], $info['js_master_secret']);
  688. }
  689. $extras = [
  690. 'id' => $this->getUserId(),
  691. 'flag' => '技师报警',
  692. ];
  693. $array = [
  694. 'extras' => $extras,
  695. ];
  696. $alias = $district_agency_user['id'] . 'js';
  697. $text = '订单号:' . $order_sn . '报警';
  698. $platform = array('ios', 'android');
  699. $client->push()
  700. ->setPlatform($platform)
  701. ->setNotificationAlert($text)
  702. ->iosNotification($text, $array)
  703. ->androidNotification($text, $array)
  704. ->addAlias("{$alias}")
  705. ->send();
  706. }
  707. $JsCallModel->allowField(true)->isUpdate(false)->save($data);
  708. $this->success('警报发送成功');
  709. }
  710. /**
  711. * @throws \think\Exception
  712. * @throws \think\exception\PDOException
  713. * 播放语音
  714. */
  715. public function play()
  716. {
  717. $js_id = $this->js_id;
  718. $id = JsOrderGrabModel::where(['js_id' => $js_id, 'status' => 1])->value('id');
  719. if ($id) {
  720. JsOrderGrabModel::where('id', $id)->update(['status' => 2]);
  721. $this->success('播放');
  722. } else {
  723. $this->error('已通知');
  724. }
  725. }
  726. /**
  727. * @throws \think\Exception
  728. * @throws \think\exception\PDOException
  729. * 播放语音取消订单
  730. */
  731. public function cancelplay()
  732. {
  733. $js_id = $this->js_id;
  734. $id = JsOrderModel::where(['jiedan_js_id' => $js_id, 'status' => 5, 'order_status' => 2])->value('id');
  735. if ($id) {
  736. JsOrderModel::where('id', $id)->update(['order_status' => 3]);
  737. $this->success('播放');
  738. } else {
  739. $this->error('已通知');
  740. }
  741. }
  742. /**
  743. * 技师删除i订单
  744. */
  745. public function deleteOrder()
  746. {
  747. $order_id = $this->request->param('order_id');
  748. $JsOrderModel = new JsOrderModel();
  749. $JsOrderModel::where('id', $order_id)->update(['js_delete' => 2]);
  750. $this->success('删除成功');
  751. }
  752. /**
  753. * 项目分类下的订单数量
  754. */
  755. public function getClassifyOrderNum()
  756. {
  757. $js_id = $this->js_id;
  758. $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
  759. $distance = cmf_get_option('distance')['distance'];
  760. $JsProjectCategoryModel = new JsProjectCategoryModel(); //项目分类
  761. $list = $JsProjectCategoryModel::where('is_show', 1)->order('list_order', 'desc')->field('id')->select()->each(function ($list) use ($js_id, $js_site_info, $distance) {
  762. $list['order_num'] = 0;
  763. $project_ids = Db::name('js_project_category_relevancy')->where('category_id', $list['id'])->field('project_id')->select();
  764. $project_ids_new = [];
  765. foreach ($project_ids as $v) {
  766. $js_project_relevancy_id = Db::name('js_project_relevancy')->where(['project_id' => $v['project_id'], 'js_id' => $js_id, 'status' => 1])->value('id');
  767. if ($js_project_relevancy_id) {
  768. if (!in_array($v['project_id'], $project_ids_new)) {
  769. array_push($project_ids_new, $v['project_id']);
  770. }
  771. }
  772. }
  773. if ($project_ids_new) {
  774. $offset = $distance / 111;
  775. $lng_offset = [$js_site_info['lng'] - $offset, $js_site_info['lng'] + $offset];
  776. $lat_offset = [$js_site_info['lat'] - $offset, $js_site_info['lat'] + $offset];
  777. $order_list = JsOrderModel::where('project_id', 'in', $project_ids_new)->where('status', 1)
  778. ->whereBetween('lat', $lat_offset)
  779. ->whereBetween('lng', $lng_offset)
  780. ->where('jiedan_js_id', 0)->field('id,lat,lng')
  781. ->count();
  782. // ->select();
  783. $list['order_num'] = $order_list;
  784. // foreach ($order_list as $value) {
  785. // $distance1 = GetDistance($value['lat'], $value['lng'], $js_site_info['lat'], $js_site_info['lng'], 2, 2);//value['lat'],/$value['lng'],$js_site_info['lat'],$js_site_info['lng'],2,2);
  786. // if ($distance >= $distance1) {
  787. // $list['order_num'] += 1;
  788. // }
  789. // }
  790. // $list['order_num'] = JsOrderModel::where('project_id', 'in', $project_ids_new)->where('status', 1)->where('jiedan_js_id', 0)->count();
  791. }
  792. return $list;
  793. });
  794. $this->success('ok', $list);
  795. }
  796. /**
  797. * 技师带接单数量
  798. */
  799. public function getOrdeNum()
  800. {
  801. $js_id = $this->js_id;
  802. $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
  803. $order_new_ids = [];
  804. foreach ($order_ids as $vo) {
  805. $order_new_ids[] = $vo['order_id'];
  806. }
  807. $num = JsOrderModel::where(['status' => 1, 'jiedan_js_id' => $js_id])->where('id', 'not in', $order_new_ids)->count();
  808. $this->success('ok', $num);
  809. }
  810. }