MassagerAction.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\service\MassagerActionService;
  4. use app\api\service\WxService;
  5. use app\api\validate\BaseApiValidate;
  6. use think\Request;
  7. /**
  8. * 技师
  9. */
  10. class MassagerAction extends MassagerBaseApi
  11. {
  12. private $service;
  13. protected $cNoNeedLogin = ["login", "wxAppLogin", "loginByMobile"];
  14. public function __construct(Request $request = null)
  15. {
  16. parent::__construct($request);
  17. $this->service = new MassagerActionService();
  18. }
  19. public function login()
  20. {
  21. $params = (new BaseApiValidate([
  22. "account" => "require",
  23. "password" => "require",
  24. ]))->checkBody();
  25. $r = $this->service->login($params["account"], $params["password"]);
  26. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  27. }
  28. public function loginByMobile()
  29. {
  30. $params = (new BaseApiValidate([
  31. "mobile" => "require",
  32. "sms_code" => "require|number",
  33. ]))->checkBody();
  34. $r = $this->service->loginByMobile($params["mobile"], $params["sms_code"]);
  35. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  36. }
  37. public function wxAppLogin()
  38. {
  39. $params = (new BaseApiValidate([
  40. "openId" => "require",
  41. "unionId" => "require"
  42. ]))->checkBody();
  43. $r = $this->service->wxAppLogin($params["openId"], $params["unionId"]);
  44. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  45. }
  46. public function bindAppWx()
  47. {
  48. $params = (new BaseApiValidate([
  49. "openId" => "require",
  50. "unionId" => "require"
  51. ]))->checkBody();
  52. $r = $this->service->bindAppWx($this->massager->id, $params["openId"], $params["unionId"]);
  53. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  54. }
  55. public function bindAppletWx()
  56. {
  57. $params = (new BaseApiValidate([
  58. "code" => "require"
  59. ]))->checkBody();
  60. $r = (new WxService())->wxLoginByApplet($params["code"]);
  61. if (0 === $r->code())
  62. $this->error($r->msg());
  63. $info = $r->data();
  64. if (!isset($info["unionid"]) || !isset($info["openid"]))
  65. $this->error("微信登录错误! unionid|openid 不能为空!");
  66. $model = new \app\api\model\massager\Massager();
  67. $massager = $model->findById($this->massager->id);
  68. if (!$massager)
  69. $this->error("用户不存在!");
  70. if ($massager["union_id"] === $info["unionid"] && $massager["applet_openid"] === $info["openid"]) {
  71. $this->success(true);
  72. }
  73. $m = $model->findByUnionId($info["unionid"]);
  74. if ($m)
  75. $this->error("该微信已经绑定助教,无法重复绑定!");
  76. $model->update([
  77. "applet_openid" => $info["openid"],
  78. "union_id" => $info["unionid"],
  79. ], ["id" => $this->massager->id]);
  80. $this->success(true);
  81. }
  82. public function fetchOrder($status = null, $page = 1, $size = 10)
  83. {
  84. $array = $status ? explode(",", $status) : [];
  85. foreach ($array as $item) {
  86. if (!in_array($item, array_merge(ALL_ORDER_STATUS, ["*"])))
  87. $this->error("状态错误!");
  88. }
  89. $r = $this->service->fetchOrder($this->massager->id, in_array("*", $array) ? [
  90. \E_ORDER_STATUS::Purchase,
  91. \E_ORDER_STATUS::Proceed,
  92. \E_ORDER_STATUS::WaitFeedback,
  93. \E_ORDER_STATUS::Finish,
  94. \E_ORDER_STATUS::Reject,
  95. \E_ORDER_STATUS::Cancel,
  96. \E_ORDER_STATUS::AdminCancel,
  97. \E_ORDER_STATUS::AutoCancel
  98. ] : $array, $page, $size);
  99. $this->success($r);
  100. }
  101. public function untakeOrderCount()
  102. {
  103. $this->success($this->service->untakeOrderCount($this->massager->id));
  104. }
  105. /**
  106. * 处理订单
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. */
  111. public function disposeOrder()
  112. {
  113. $params = (new BaseApiValidate([
  114. "order_id" => "require|number",
  115. "type" => "require",
  116. "lng" => "require|number",
  117. "lat" => "require|number"
  118. ]))->checkBody();
  119. if (!in_array($params["type"], ALL_ORDER_PROGRESS_TYPE))
  120. $this->error("打卡type错误");
  121. $r = $this->service->dispose($this->massager->id, $params["order_id"], $params["type"], $params["lng"], $params["lat"], isset($params["card_image"]) ? $params["card_image"] : null);
  122. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  123. }
  124. /**
  125. * 拒绝接单
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. */
  130. public function rejectOrder()
  131. {
  132. $params = (new BaseApiValidate([
  133. "order_id" => "require|number",
  134. "reason" => "require"
  135. ]))->checkBody();
  136. $r = $this->service->rejectOrder($this->massager->id, $params["order_id"], $params["reason"]);
  137. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  138. }
  139. public function getMassagerInfo()
  140. {
  141. $params = (new BaseApiValidate([
  142. "massager_id" => "require|number",
  143. ]))->checkBody();
  144. $r = $this->service->getMassagerInfo($params["massager_id"]);
  145. $r ? $this->success($r) : $this->error("助教信息不存在!");
  146. }
  147. public function updateInfo()
  148. {
  149. $params = (new BaseApiValidate([
  150. // "description" => "",
  151. "radius" => "number",
  152. "height" => "number",
  153. "weight" => "number",
  154. "free_travel_km" => "number",
  155. ]))->checkBody();
  156. $this->service->modify($this->massager->id, $params);
  157. $this->success();
  158. }
  159. public function updateLocation()
  160. {
  161. $params = (new BaseApiValidate([
  162. "city_code" => "require|number",
  163. "lng" => "require|number",
  164. "lat" => "require|number",
  165. ]))->checkBody();
  166. $r = $this->service->updateLocation($this->massager->id, (int)$params["city_code"], $params["lng"], $params["lat"]);
  167. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  168. }
  169. public function workClockIn()
  170. {
  171. $r = $this->service->workClockIn($this->massager->id);
  172. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  173. }
  174. public function online()
  175. {
  176. $r = $this->service->online($this->massager->id);
  177. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  178. }
  179. public function findWallet()
  180. {
  181. $r = $this->service->findWallet($this->massager->id);
  182. $this->success($r);
  183. }
  184. public function fetchComment()
  185. {
  186. $params = (new BaseApiValidate([
  187. "negative" => "between:0,1",
  188. "page" => "require|number",
  189. "size" => "require|number",
  190. ]))->checkBody();
  191. $r = $this->service->fetchComment($this->massager->id, isset($params["negative"]) ? $params["negative"] : null, $params["page"], $params["size"]);
  192. $this->success($r);
  193. }
  194. public function allegedly()
  195. {
  196. $params = (new BaseApiValidate([
  197. "comment_id" => "require|number",
  198. "allegedly_text" => "require",
  199. ]))->checkBody();
  200. $r = $this->service->allegedly($this->massager->id, $params["comment_id"], $params["allegedly_text"]);
  201. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  202. }
  203. public function areaVisa()
  204. {
  205. $params = (new BaseApiValidate([
  206. "new_city_code" => "require|number",
  207. "description" => "require",
  208. "lng" => "require|number",
  209. "lat" => "require|number",
  210. ]))->checkBody();
  211. $r = $this->service->areaVisa($this->massager->id, $params["new_city_code"], $params["description"], $params["lng"], $params["lat"]);
  212. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  213. }
  214. public function closeAccount()
  215. {
  216. $params = (new BaseApiValidate([
  217. "sms_code" => "require|number"
  218. ]))->checkBody();
  219. $r = $this->service->closeAccount($this->massager->id, $params["sms_code"]);
  220. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  221. }
  222. public function feedback()
  223. {
  224. $params = (new BaseApiValidate([
  225. // "type" => "require",
  226. "reason" => "require",
  227. "mobile" => "require",
  228. "content" => "require",
  229. "relation_type" => "require",
  230. ]))->checkBody();
  231. if (!in_array($params["relation_type"], ['platform', 'agency', 'store', 'massager', 'user', 'other']))
  232. $this->error("relation_type");
  233. $r = $this->service->feedback(
  234. $this->massager->id,
  235. isset($params["type"]) ? $params["type"] : 'complaint',
  236. $params["content"],
  237. isset($params["images"]) ? $params["images"] : null,
  238. $params["reason"],
  239. $params["mobile"],
  240. isset($params["relation_type"]) ? $params["relation_type"] : null,
  241. isset($params["relation_id"]) ? $params["relation_id"] : null,
  242. isset($params["relation_name"]) ? $params["relation_name"] : null
  243. );
  244. $this->success($r);
  245. }
  246. public function modify()
  247. {
  248. $params = $this->request->param();
  249. if (isset($params["mobile"])) {
  250. if (11 !== strlen($params["mobile"]))
  251. $this->error("手机号码格式错误");
  252. if (!isset($params["sms_code"]))
  253. $this->error("验证码不能为空");
  254. }
  255. $r = $this->service->modify($this->massager->id, $params);
  256. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  257. }
  258. public function fetchMassagerPhoto()
  259. {
  260. $params = (new BaseApiValidate([
  261. "massager_id" => "require|number",
  262. ]))->checkBody();
  263. $r = $this->service->fetchMassagerPhoto($params["massager_id"]);
  264. is_null($r) ? $this->error("数据不存在") : $this->success($r);
  265. }
  266. public function fetchTripAmountOrder()
  267. {
  268. $params = (new BaseApiValidate([
  269. "page" => "require|number",
  270. "size" => "require|number"
  271. ]))->checkBody();
  272. $r = $this->service->fetchTripAmountOrder($this->massager->id, $params["page"], $params["size"]);
  273. $this->success($r);
  274. }
  275. public function fetchDurationCount()
  276. {
  277. $this->success($this->service->fetchDurationCount($this->massager->id));
  278. }
  279. public function fetchBill()
  280. {
  281. $params = (new BaseApiValidate([
  282. 'currency_type' => 'require',
  283. 'change_types' => 'require',
  284. 'page' => 'require|number',
  285. 'size' => 'require|number',
  286. ]))->checkBody();
  287. if (!in_array($params["currency_type"], [\E_USER_BILL_CURRENCY_TYPE::Money, \E_USER_BILL_CURRENCY_TYPE::Score]))
  288. $this->error("currency_type error");
  289. $r = $this->service->fetchBill(
  290. $this->massager->id,
  291. $params["currency_type"],
  292. explode(",", (string)$params["change_types"]),
  293. $params["page"],
  294. $params["size"]
  295. );
  296. $this->success($r);
  297. }
  298. public function fetchShareProfit()
  299. {
  300. $r = $this->service->fetchShareProfit($this->massager->id);
  301. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  302. }
  303. public function tabulateData()
  304. {
  305. $r = $this->service->tabulateData($this->massager->id);
  306. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  307. }
  308. public function deposit()
  309. {
  310. $params = (new BaseApiValidate([
  311. 'platform' => 'require',
  312. 'amount' => 'require|between:1,100000',
  313. ]))->checkBody();
  314. if (!in_array($params["platform"], [\E_ORDER_PAY_TYPE::Wechat, \E_ORDER_PAY_TYPE::ALi, \E_ORDER_PAY_TYPE::Bank]))
  315. $this->error("platform error");
  316. $r = $this->service->deposit(
  317. $this->massager->id,
  318. $params["platform"],
  319. fixed2Float($params["amount"])
  320. );
  321. $r->code() == 1 ? $this->success($r->data(), $r->msg()) : $this->error($r->msg(), null, $r->code());
  322. }
  323. public function fetchSystemMessage()
  324. {
  325. $params = (new BaseApiValidate([
  326. 'page' => 'require|number',
  327. 'size' => 'require|number',
  328. ]))->checkBody();
  329. $this->success($this->service->fetchSystemMessage($this->massager->id, $params["page"], $params["size"]));
  330. }
  331. public function getUnreadMessageCount()
  332. {
  333. $this->success($this->service->getUnreadMessageCount($this->massager->id));
  334. }
  335. public function resetPassword()
  336. {
  337. $params = (new BaseApiValidate([
  338. "mobile" => "require|length:11",
  339. "sms_code" => "require|number",
  340. "new_password" => "require",
  341. ]))->checkBody();
  342. $r = $this->service->resetPassword($params["mobile"], $params["sms_code"], $params["new_password"]);
  343. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  344. }
  345. public function fetchDiffAmountDetailsByYm($year = null, $month = null)
  346. {
  347. $r = $this->service->fetchDiffAmountDetailsByYm($this->massager->id, $this->massager["city_code"], $year, $month);
  348. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  349. }
  350. // 结算本月Order
  351. public function closingOrderPerformanceByYm()
  352. {
  353. $r = $this->service->closingOrderPerformanceByYm($this->massager->id);
  354. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  355. }
  356. public function fetchClosingOrderPerformance($page = null, $size = null)
  357. {
  358. $this->success($this->service->fetchClosingOrderPerformance($this->massager->id, $page, $size));
  359. }
  360. public function fetchInteriorScoreDetails($year = null, $month = null)
  361. {
  362. if (null === $year)
  363. $year = date("Y");
  364. if (null === $month)
  365. $month = date("m");
  366. $this->success(
  367. $this->service->fetchInteriorScoreDetails($this->massager->id, $year, $month)
  368. );
  369. }
  370. public function uploadContract($contract_file = null)
  371. {
  372. if (is_null($contract_file))
  373. $this->error("请上传合同附件");
  374. $this->success($this->service->uploadContract($this->massager->id, $contract_file));
  375. }
  376. /**
  377. * @throws \think\db\exception\DataNotFoundException
  378. * @throws \think\db\exception\ModelNotFoundException
  379. * @throws \think\exception\DbException
  380. */
  381. public function publishDynamic()
  382. {
  383. $params = (new BaseApiValidate([
  384. "type" => "require",
  385. "massager_id" => "require|number",
  386. "topic_id" => "number",
  387. "description" => "require",
  388. "attachment_files" => "require",
  389. "city_code" => "require",
  390. "address" => "require",
  391. "lng" => "require",
  392. "lat" => "require"
  393. ]))->checkBody();
  394. $r = $this->service->publishDynamic($this->massager->id, $params);
  395. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  396. }
  397. public function appeal()
  398. {
  399. $params = (new BaseApiValidate([
  400. "order_id" => "require|number",
  401. "appeal_reason" => "require",
  402. ]))->checkBody();
  403. $r = $this->service->appeal($this->massager->id, $params["order_id"], $params["appeal_reason"]);
  404. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  405. }
  406. public function setNoWorkPeriod()
  407. {
  408. $params = (new BaseApiValidate([
  409. "range" => "require"
  410. ]))->checkBody();
  411. $r = $this->service->setNoWorkPeriod($this->massager->id, $params["range"]);
  412. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  413. }
  414. public function fetchNoWorkPeriod()
  415. {
  416. $this->success($this->service->fetchNoWorkPeriod($this->massager->id));
  417. }
  418. public function delNoWorkPeriod()
  419. {
  420. $params = (new BaseApiValidate([
  421. "id" => "require"
  422. ]))->checkBody();
  423. $this->success($this->service->delNoWorkPeriod($params["id"]));
  424. }
  425. public function fetchInviteQrCode()
  426. {
  427. $url = "https://pbh5.xunsoftware.com/pages/teacher/settle?parent_id={$this->massager->id}";
  428. if (is_null($this->massager->invite_qr_code)) {
  429. $qr_code = \qrcodeBase64("https://pbh5.xunsoftware.com/pages/teacher/settle", ["parent_id" => $this->massager->id]);
  430. (new \app\api\model\massager\Massager())->update([
  431. "invite_qr_code" => $qr_code
  432. ], ["id" => $this->massager->id]);
  433. $this->success($qr_code);
  434. }
  435. $this->success([
  436. "invite_qr_code" => $this->massager->invite_qr_code,
  437. "link" => $url
  438. ]);
  439. }
  440. }