MchController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\constants\OptionSetting;
  9. use app\jobs\StoreSyncJob;
  10. use app\models\Admin;
  11. use app\models\BonusPoolLevel;
  12. use app\models\Cash;
  13. use app\models\Form;
  14. use app\models\IntegralSetting;
  15. use app\models\MchBrands;
  16. use app\models\MchStaff;
  17. use app\models\OldUserTreePath;
  18. use app\models\Option;
  19. use app\models\Order;
  20. use app\models\OrderRefund;
  21. use app\models\SaaSLeaguePriceLog;
  22. use app\models\ShareDetail;
  23. use app\models\ShareHolder;
  24. use app\models\ShareHolderFrostLog;
  25. use app\models\ShareHolderLevelLog;
  26. use app\models\ShareHolderOutLog;
  27. use app\models\ShareHolderParentOutLog;
  28. use app\models\Store;
  29. use app\models\StoreTemplate;
  30. use app\models\SaasCategory;
  31. use app\models\StoreCopy;
  32. use app\models\User;
  33. use app\models\UserTreePath;
  34. use app\modules\admin\models\MchBrandsForm;
  35. use app\modules\admin\models\MerchantForm;
  36. use app\modules\admin\models\SubmitFormForm;
  37. use app\modules\client\models\v1\LoginForm;
  38. use app\utils\Delivery\Delivery;
  39. use Yii;
  40. use app\modules\admin\models\StoreForm;
  41. use app\modules\admin\models\SaasCategoryForm;
  42. use yii\base\BaseObject;
  43. use app\models\SaasUser;
  44. use app\models\Salesman;
  45. use yii\helpers\Json;
  46. use app\utils\IotCloudHelper;
  47. use app\constants\Kefu;
  48. use app\models\Supplier;
  49. use app\models\Mch;
  50. use app\modules\admin\models\MchForm;
  51. use app\models\MchGoodsCat;
  52. class MchController extends BaseController
  53. {
  54. public function actionTest()
  55. {
  56. $a = MchForm::accountMoneyAdd(Order::findOne(13303));
  57. var_dump($a);
  58. die;
  59. $form = new MchForm();
  60. $id = input_params('id');
  61. $status = input_params('status');
  62. $result = $form->goodsCatStatus($id, $status);
  63. return $this->asJson($result);
  64. }
  65. /**
  66. * 商户设置
  67. */
  68. public function actionSetting()
  69. {
  70. $store_id = get_store_id();
  71. $form = new MchForm();
  72. $form->attributes = all_params();
  73. $form->store_id = $store_id;
  74. $result = $form->mchSetting();
  75. return $this->asJson([
  76. 'code' => 0,
  77. 'msg' => 'ok',
  78. 'data' => $result,
  79. ]);
  80. }
  81. /**
  82. * 商户设置
  83. */
  84. public function actionSettingSave()
  85. {
  86. $store_id = get_store_id();
  87. $form = new MchForm();
  88. $form->store_id = $store_id;
  89. $conf = input_params('conf', []);
  90. $result = $form->mchSettingSave($conf);
  91. return $this->asJson([
  92. 'code' => 0,
  93. 'msg' => 'ok',
  94. ]);
  95. }
  96. /**
  97. * 商户
  98. */
  99. public function actionInfo()
  100. {
  101. $form = new MchForm();
  102. $form->mch_id = input_params('id', get_mch_id());
  103. $result = $form->mchInfo();
  104. return $this->asJson($result);
  105. }
  106. /**
  107. * 商户列表
  108. */
  109. public function actionList()
  110. {
  111. $store_id = get_store_id();
  112. $form = new MchForm();
  113. $form->attributes = all_params();
  114. $form->store_id = $store_id;
  115. $result = $form->mchList();
  116. return $this->asJson($result);
  117. }
  118. /**
  119. * 商户列表
  120. */
  121. public function actionSelectList()
  122. {
  123. $store_id = get_store_id();
  124. $form = new MchForm();
  125. $form->attributes = all_params();
  126. $form->store_id = $store_id;
  127. $result = $form->mchSelectList();
  128. return $this->asJson($result);
  129. }
  130. /**
  131. * 商户
  132. */
  133. public function actionSave()
  134. {
  135. $store_id = get_store_id();
  136. checkReplay([$store_id], 10);
  137. $form = new MchForm();
  138. $form->attributes = all_params();
  139. $form->store_id = $store_id;
  140. $result = $form->mchSave();
  141. return $this->asJson($result);
  142. }
  143. /**
  144. * 商户首页
  145. */
  146. public function actionHomeSave()
  147. {
  148. $form = new MchForm();
  149. $form->id = get_mch_id();
  150. $form->home_type = input_params('home_type');
  151. $result = $form->mchHomeSave();
  152. return $this->asJson($result);
  153. }
  154. /**
  155. * 修改商户营业状态
  156. */
  157. public function actionOpen()
  158. {
  159. $store_id = get_store_id();
  160. $form = new MchForm();
  161. $form->attributes = all_params();
  162. $form->store_id = $store_id;
  163. $result = $form->mchOpen();
  164. return $this->asJson($result);
  165. }
  166. /**
  167. * 商户删除
  168. */
  169. public function actionDel()
  170. {
  171. $store_id = get_store_id();
  172. $form = new MchForm();
  173. $form->attributes = all_params();
  174. $form->store_id = $store_id;
  175. $result = $form->mchDel();
  176. return $this->asJson($result);
  177. }
  178. /**
  179. * 商户申请列表
  180. */
  181. public function actionAuditList()
  182. {
  183. $store_id = get_store_id();
  184. $form = new MchForm();
  185. $form->attributes = all_params();
  186. $form->store_id = $store_id;
  187. $result = $form->mchAuditList();
  188. return $this->asJson($result);
  189. }
  190. /**
  191. * 商户审核
  192. */
  193. public function actionAuditStatus()
  194. {
  195. $store_id = get_store_id();
  196. $form = new MchForm();
  197. $form->attributes = all_params();
  198. $form->store_id = $store_id;
  199. $result = $form->mchAuditStatus();
  200. return $this->asJson($result);
  201. }
  202. /**
  203. * 商户申请删除
  204. */
  205. public function actionAuditDel()
  206. {
  207. $store_id = get_store_id();
  208. $form = new MchForm();
  209. $form->attributes = all_params();
  210. $form->store_id = $store_id;
  211. $result = $form->mchAuditDel();
  212. return $this->asJson($result);
  213. }
  214. /**
  215. * 商户分类列表
  216. */
  217. public function actionCommonCatList()
  218. {
  219. $store_id = get_store_id();
  220. $form = new MchForm();
  221. $form->attributes = all_params();
  222. $form->store_id = $store_id;
  223. $result = $form->mchCommonCatList();
  224. return $this->asJson($result);
  225. }
  226. /**
  227. * 商户分类列表
  228. */
  229. public function actionCommonCatSelectList()
  230. {
  231. $store_id = get_store_id();
  232. $form = new MchForm();
  233. $form->attributes = all_params();
  234. $form->store_id = $store_id;
  235. $result = $form->mchCommonCatSelectList(0);
  236. return $this->asJson($result);
  237. }
  238. /**
  239. * 商户分类
  240. */
  241. public function actionCommonCatSave()
  242. {
  243. $store_id = get_store_id();
  244. $form = new MchForm();
  245. $form->attributes = all_params();
  246. $form->store_id = $store_id;
  247. $result = $form->mchCommonCatSave();
  248. return $this->asJson($result);
  249. }
  250. /**
  251. * 商户分类展示
  252. */
  253. public function actionCommonCatShow()
  254. {
  255. $store_id = get_store_id();
  256. $form = new MchForm();
  257. $form->attributes = all_params();
  258. $form->store_id = $store_id;
  259. $result = $form->mchCommonCatShow();
  260. return $this->asJson($result);
  261. }
  262. /**
  263. * 商户分类删除
  264. */
  265. public function actionCommonCatDel()
  266. {
  267. $store_id = get_store_id();
  268. $form = new MchForm();
  269. $form->attributes = all_params();
  270. $form->store_id = $store_id;
  271. $result = $form->mchCommonCatDel();
  272. return $this->asJson($result);
  273. }
  274. /**
  275. * 商户商品审核
  276. */
  277. public function actionGoodsAudit()
  278. {
  279. $store_id = get_store_id();
  280. $form = new MchForm();
  281. $form->attributes = all_params();
  282. $form->store_id = $store_id;
  283. $result = $form->mchGoodsAudit();
  284. return $this->asJson($result);
  285. }
  286. /**
  287. * 获取分类列表
  288. */
  289. public function actionGoodsCatList()
  290. {
  291. $is_show = input_params('is_show', 1);
  292. $mch_id = get_mch_id();
  293. $form = new MchForm();
  294. $result = $form->goodsCatList($mch_id, $is_show);
  295. $is_add_goods = Option::get('is_add_goods', get_store_id(), 'store', 1)['value'];
  296. return $this->asJson([
  297. 'code' => 0,
  298. 'data' => [
  299. 'list' => $result,
  300. 'is_add_goods' => (int)$is_add_goods
  301. ]
  302. ]);
  303. }
  304. /**
  305. * 分类保存
  306. */
  307. public function actionGoodsCatSave()
  308. {
  309. $mch_id = get_mch_id();
  310. $form = new MchForm();
  311. $form->attributes = all_params();
  312. $form->mch_id = $mch_id;
  313. $result = $form->goodsCatSave();
  314. return $this->asJson($result);
  315. }
  316. /**
  317. * 分类 显示、隐藏、删除
  318. */
  319. public function actionGoodsCatStatus()
  320. {
  321. $form = new MchForm();
  322. $id = input_params('id');
  323. $status = input_params('status');
  324. $result = $form->goodsCatStatus($id, $status);
  325. return $this->asJson($result);
  326. }
  327. /**
  328. * 佣金
  329. */
  330. public function actionAccountLog()
  331. {
  332. $mch_id = get_mch_id();
  333. $form = new MchForm();
  334. $form->attributes = all_params();
  335. $form->mch_id = $mch_id;
  336. $result = $form->accountLog();
  337. return $this->asJson($result);
  338. }
  339. /**
  340. * 提现
  341. */
  342. public function actionMchCashSubmit()
  343. {
  344. $price = input_params('cash');
  345. $type = input_params('type');
  346. $name = input_params('name', '');
  347. $account = input_params('account', '');
  348. $bank = input_params('bank', '');
  349. $mch_id = get_mch_id();
  350. $form = new MchForm();
  351. $form->attributes = all_params();
  352. $form->mch_id = $mch_id;
  353. $result = $form->mchCashSubmit($price, $type, get_user_id(), $name, $account, $bank);
  354. return $this->asJson($result);
  355. }
  356. /**
  357. * 设置客服
  358. */
  359. public function actionSetKefuInfo()
  360. {
  361. $mch_id = get_mch_id();
  362. $form = new MchForm();
  363. $form->attributes = all_params();
  364. $form->mch_id = $mch_id;
  365. $result = $form->setKefuInfo();
  366. return $this->asJson($result);
  367. }
  368. /**
  369. * 设置客服
  370. */
  371. public function actionGetKefuInfo()
  372. {
  373. $mch_id = get_mch_id();
  374. $form = new MchForm();
  375. $form->attributes = all_params();
  376. $form->mch_id = $mch_id;
  377. $result = $form->getKefuInfo();
  378. return $this->asJson($result);
  379. }
  380. /**
  381. * 入住商品牌列表
  382. * @author: hankaige
  383. * @Time: 2025/5/12 15:04
  384. */
  385. public function actionGetBrandsList()
  386. {
  387. $form = new MchBrandsForm();
  388. $form->attributes = get_params();
  389. $result = $form->getBrandList();
  390. return $this->asJson(['code' => 0, 'msg' => '请求成功', 'data' => $result]);
  391. }
  392. /**
  393. * 获取一个入住商品牌分类数据
  394. * @author: hankaige
  395. * @Time: 2025/5/12 15:05
  396. */
  397. public function actionGetBrandsItem()
  398. {
  399. $form = new MchBrandsForm();
  400. $form->attributes = get_params();
  401. $result = $form->getBrandItem();
  402. return $this->asJson(['code' => 0, 'msg' => '请求成功', 'data' => $result]);
  403. }
  404. /**
  405. * 编辑一个入住商品牌分类
  406. * @author: hankaige
  407. * @Time: 2025/5/12 15:06
  408. */
  409. public function actionBrandsSave()
  410. {
  411. $form = new MchBrandsForm();
  412. $form->attributes = post_params();
  413. $result = $form->brandsSave();
  414. return $this->asJson($result);
  415. }
  416. /**
  417. * 删除一个品牌分类
  418. * @author: hankaige
  419. * @Time: 2025/5/12 15:06
  420. */
  421. public function actionBrandsDel()
  422. {
  423. $form = new MchBrandsForm();
  424. $form->attributes = get_params();
  425. $result = $form->deleteBrand();
  426. return $this->asJson($result);
  427. }
  428. /**
  429. * 修改品牌分类状态
  430. * @return \yii\web\Response
  431. * @author: hankaige
  432. * @Time: 2025/5/13 11:11
  433. */
  434. public function actionChangeBrandsStatus()
  435. {
  436. $form = new MchBrandsForm();
  437. $form->attributes = get_params();
  438. $result = $form->changeBrandsStatus();
  439. return $this->asJson($result);
  440. }
  441. /**
  442. * 入住商编辑的时品牌分类选择列表数据 无分页
  443. * @return \yii\web\Response
  444. * @author: hankaige
  445. * @Time: 2025/5/14 09:16
  446. */
  447. public function actionGetBrandsSelectList()
  448. {
  449. $form = new MchBrandsForm();
  450. $result = $form->getBrandsSelectList();
  451. return $this->asJson(['code' => 0, 'msg' => '请求成功', 'data' => $result]);
  452. }
  453. public function actionStaffList()
  454. {
  455. $name = get_params('name');
  456. $mobile = get_params('mobile');
  457. $start_time = get_params('start_time');
  458. $end_time = get_params('end_time');
  459. $mch_id = get_mch_id();
  460. $store_id = get_store_id();
  461. $query = MchStaff::find()->alias('ms')->leftJoin(['mch' => Mch::tableName()], 'mch.id=ms.mch_id')->where(['ms.is_delete' => 0])->orderBy("ms.created_at desc, ms.updated_at desc");
  462. if ($mch_id !== null) {
  463. if ($mch_id <= 0) {
  464. $query->andWhere(['AND', ['ms.mch_id' => [0, -1]], ['IS', 'mch.id', NULL]]);
  465. } else {
  466. $query->andWhere(['ms.mch_id' => $mch_id, 'mch.is_delete' => 0]);
  467. }
  468. }
  469. if ($store_id > 0) {
  470. $query->andWhere(['ms.store_id' => $store_id]);
  471. }
  472. if ($name) {
  473. $query->andWhere(['like', 'ms.name', $name]);
  474. }
  475. if ($mobile) {
  476. $query->andWhere(['like', 'ms.mobile', $mobile]);
  477. }
  478. if ($start_time) {
  479. $query->andWhere(['>=', 'ms.created_at', strtotime($start_time)]);
  480. }
  481. if ($end_time) {
  482. $query->andWhere(['<=', 'ms.created_at', strtotime($end_time)]);
  483. }
  484. $list = pagination_make($query);
  485. foreach ($list['list'] as &$val) {
  486. $user = User::findOne($val['user_id']);
  487. $val['avatar'] = $user->avatar_url;
  488. $val['mch_name'] = Mch::findOne($val['mch_id'])->name;
  489. if ($val['mch_id'] <= 0) {
  490. $val['mch_name'] = Store::findOne($val['store_id'])->name;
  491. }
  492. $val['nickname'] = $user->nickname;
  493. }
  494. return $this->asJson([
  495. 'code' => 0,
  496. 'msg' => 'success',
  497. 'data' => [
  498. 'data' => $list['list'],
  499. 'pageNo' => $list['pageNo'],
  500. 'totalCount' => $list['totalCount']
  501. ]
  502. ]);
  503. }
  504. public function actionStaffAdd()
  505. {
  506. $store_id = get_store_id();
  507. $mch_id = get_mch_id();
  508. $name = post_params('name');
  509. $mobile = post_params('mobile');
  510. $user_id = post_params('user_id');
  511. if (empty($name) || empty($mobile) || empty($user_id)) {
  512. return $this->asJson([
  513. 'code' => 1,
  514. 'msg' => '参数有误'
  515. ]);
  516. }
  517. $user = User::findOne($user_id);
  518. if (!$user) {
  519. return $this->asJson([
  520. 'code' => 1,
  521. 'msg' => '用户不存在'
  522. ]);
  523. }
  524. $staff = MchStaff::findOne(['store_id' => $store_id, 'user_id' => $user->id, 'is_delete' => 0]);
  525. if ($staff) {
  526. return $this->asJson([
  527. 'code' => 1,
  528. 'msg' => '该员工已在其他商户下,请重新绑定'
  529. ]);
  530. }
  531. $md_staff = new MchStaff();
  532. $md_staff->store_id = $store_id;
  533. $md_staff->mch_id = $mch_id;
  534. $md_staff->user_id = $user->id;
  535. $md_staff->name = $name;
  536. $md_staff->mobile = $mobile;
  537. if (!$md_staff->save()) {
  538. return $this->asJson([
  539. 'code' => 1,
  540. 'msg' => $md_staff->errors[0]
  541. ]);
  542. }
  543. return $this->asJson([
  544. 'code' => 0,
  545. 'msg' => '保存成功'
  546. ]);
  547. }
  548. /**
  549. * 更新状态
  550. * @return \yii\web\Response
  551. */
  552. public function actionStaffStatus()
  553. {
  554. $id = post_params('id');
  555. $type = post_params('type');
  556. $status = post_params('status');
  557. if (empty($id) || !is_array($id)) {
  558. return $this->asJson([
  559. 'code' => 1,
  560. 'msg' => '参数有误'
  561. ]);
  562. }
  563. if (!in_array($status, [0, 1])) {
  564. return $this->asJson([
  565. 'code' => 1,
  566. 'msg' => '状态参数有误'
  567. ]);
  568. }
  569. if ($type == 'is_disable') {
  570. MchStaff::updateAll(['is_disable' => $status], ['in', 'id', $id]);
  571. }
  572. if ($type == 'is_delete') {
  573. MchStaff::updateAll(['is_delete' => $status], ['in', 'id', $id]);
  574. }
  575. return $this->asJson([
  576. 'code' => 0,
  577. 'msg' => '更新成功'
  578. ]);
  579. }
  580. }