MassagerAction.php 17 KB

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