MdController.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  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\jobs\LgCashJob;
  9. use app\models\AccountLog;
  10. use app\models\Admin;
  11. use app\models\AgentFrontBind;
  12. use app\models\Cash;
  13. use app\models\CashExt;
  14. use app\models\Color;
  15. use app\models\Coupon;
  16. use app\models\District;
  17. use app\models\Goods;
  18. use app\models\Lg;
  19. use app\models\Md;
  20. use app\models\MdGoods;
  21. use app\models\MdProfit;
  22. use app\models\MdStaff;
  23. use app\models\Order;
  24. use app\models\OrderDetail;
  25. use app\models\Qrcode;
  26. use app\models\SaasUser;
  27. use app\models\Salesman;
  28. use app\models\Share;
  29. use app\models\Shop;
  30. use app\models\Store;
  31. use app\models\User;
  32. use app\models\WechatConfig;
  33. use app\modules\admin\models\DriverForm;
  34. use app\modules\admin\models\InventoryForm;
  35. use app\modules\admin\models\MdForm;
  36. use app\modules\admin\models\MdGroupActivitiesForm;
  37. use app\modules\admin\models\MdGroupDriverForm;
  38. use app\modules\admin\models\MdSettingForm;
  39. use app\modules\admin\models\QrcodeForm;
  40. use app\utils\Alipay\Alipay;
  41. use app\utils\Export;
  42. use app\utils\ExportList;
  43. use app\utils\LgApi;
  44. use app\utils\Notice\NoticeSend;
  45. use app\utils\OrderNo;
  46. use yii\base\BaseObject;
  47. use yii\helpers\Json;
  48. use app\jobs\BatchDownGoodsJob;
  49. use app\models\Option;
  50. use app\models\StoreMoneyLog;
  51. class MdController extends BaseController
  52. {
  53. /**
  54. * 门店列表
  55. */
  56. public function actionList()
  57. {
  58. $param = get_params();
  59. $form = new MdForm();
  60. $form->scenario = $form::SCENARIO_LIST;
  61. $form->attributes = $param;
  62. return $this->asJson($form->searchMd());
  63. }
  64. /**
  65. * 门店列表
  66. */
  67. public function actionAuditList()
  68. {
  69. $param = get_params();
  70. $form = new MdForm();
  71. $form->attributes = $param;
  72. return $this->asJson($form->searchAudit());
  73. }
  74. /**
  75. * 门店添加
  76. */
  77. public function actionAdd()
  78. {
  79. $form = new MdForm();
  80. $form->scenario = $form::SCENARIO_ADD;
  81. $form->attributes = post_params();
  82. $form->store_id = get_store_id();
  83. return $this->asJson($form->saveMd());
  84. }
  85. /**
  86. * 门店编辑
  87. */
  88. public function actionDetail()
  89. {
  90. $id = get_md_id();
  91. $md = Md::findOne($id);
  92. $md->password = "";
  93. $md->cat_id = intval($md->cat_id) ?: null;
  94. $res = [
  95. 'code' => 0,
  96. 'data' => $md
  97. ];
  98. return $this->asJson($res);
  99. }
  100. /**
  101. * 门店编辑
  102. */
  103. public function actionEdit()
  104. {
  105. $param = post_params();
  106. $form = new MdForm();
  107. $form->scenario = $form::SCENARIO_EDIT;
  108. $form->attributes = $param;
  109. $form->store_id = get_store_id();
  110. return $this->asJson($form->saveMd());
  111. }
  112. /**
  113. * 删除门店
  114. */
  115. public function actionDel()
  116. {
  117. //主键id用key标识并进行获取
  118. $param = get_params('key');
  119. $form = new MdForm();
  120. $form->scenario = $form::SCENARIO_DEL;
  121. $form->id = $param;
  122. return $this->asJson($form->delMd());
  123. }
  124. /**
  125. * 审核
  126. */
  127. public function actionAudit()
  128. {
  129. $param = post_params();
  130. $form = new MdForm();
  131. $form->scenario = $form::SCENARIO_AUDIT;
  132. $form->attributes = $param;
  133. return $this->asJson($form->auditMd());
  134. }
  135. /**
  136. * 审核门店
  137. * @return \yii\web\Response
  138. */
  139. public function actionBatchAudit()
  140. {
  141. $id = post_params('id');
  142. $status = post_params('shop_audit');
  143. if (!in_array($status, [Md::SHOP_AUDIT_NO, Md::SHOP_AUDIT_YES])) {
  144. return $this->asJson([
  145. 'code' => 1,
  146. 'msg' => '参数错误'
  147. ]);
  148. }
  149. if (empty($id) || !is_array($id)) {
  150. return $this->asJson([
  151. 'code' => 1,
  152. 'msg' => '参数错误'
  153. ]);
  154. }
  155. $t = \Yii::$app->db->beginTransaction();
  156. Md::updateAll(['shop_audit' => $status, 'audit_time' => time()], ['in', 'id', $id]);
  157. if ($status == 1) {
  158. foreach ($id as $value) {
  159. $md = Md::findOne($value);
  160. if ($md->user_id > 0) {
  161. $md->manager = $md->user_id;
  162. if (!$md->save()) {
  163. $t->rollBack();
  164. return $this->asJson([
  165. 'code' => 1,
  166. 'msg' => $md->errors[0]
  167. ]);
  168. }
  169. $saas_user = SaasUser::findOne($md->user_id);
  170. $md_staff = MdStaff::findOne(['saas_user_id' => $md->user_id, 'is_delete' => 0, 'store_id' => get_store_id()]);
  171. if (!$md_staff) {
  172. $md_staff = new MdStaff();
  173. $md_staff->saas_user_id = $md->user_id;
  174. $md_staff->is_manager = 1;
  175. $md_staff->store_id = get_store_id();
  176. $md_staff->md_id = $md->id;
  177. $md_staff->name = $saas_user->name;
  178. $md_staff->mobile = $saas_user->mobile;
  179. if (!$md_staff->save()) {
  180. $t->rollBack();
  181. return $this->asJson([
  182. 'code' => 1,
  183. 'msg' => $md_staff->errors[0]
  184. ]);
  185. }
  186. //兼容老版本
  187. $user_name = $md->user_name ?: $md->mobile;
  188. $exist_admin = Admin::findOne(['type' => 'md', 'type_id' => $md->id, 'username' => $user_name, 'store_id' => get_store_id()]);
  189. if ($exist_admin) {
  190. $exist_admin->is_delete = 1;
  191. if (!$exist_admin->save()) {
  192. $t->rollBack();
  193. return $this->asJson([
  194. 'code' => 1,
  195. 'msg' => $exist_admin->errors[0]
  196. ]);
  197. }
  198. }
  199. $admin = Admin::find()->where(['username' => $user_name, 'is_delete' => 0])->one();
  200. if ($admin) {
  201. $t->rollBack();
  202. return $this->asJson([
  203. 'code' => 1,
  204. 'msg' => '保存失败,管理员账户已经存在'
  205. ]);
  206. }
  207. // 自动创建admin账号
  208. $admin = new Admin();
  209. $admin->store_id = get_store_id();
  210. $admin->access_token = \Yii::$app->security->generateRandomString();
  211. $admin->username = $md->user_name;
  212. $admin->password = $md->password;
  213. $admin->mobile = $md->mobile;
  214. $admin->avatar = $saas_user->avatar;
  215. $admin->name = $md->name;
  216. $admin->type = 'md';
  217. $admin->type_id = $md->id;
  218. if (!$admin->save()) {
  219. $t->rollBack();
  220. return $this->asJson([
  221. 'code' => 1,
  222. 'msg' => $admin->errors[0]
  223. ]);
  224. }
  225. }
  226. }
  227. }
  228. // 消息队列处理批量下架门店商品
  229. // queue_push(new BatchDownGoodsJob(['ids' => $id, 'store_id' => get_store_id()]));
  230. }
  231. $t->commit();
  232. return $this->asJson([
  233. 'code' => 0,
  234. 'msg' => '审核成功'
  235. ]);
  236. }
  237. /**
  238. * 手动更新平台规格数据
  239. * @return \yii\web\Response
  240. */
  241. public function actionSetAttr()
  242. {
  243. $goods_id = post_params('goods_id');
  244. // $md_id = get_md_id();
  245. if (!is_array($goods_id) || empty($goods_id)) {
  246. return $this->asJson([
  247. 'code' => 1,
  248. 'msg' => '参数错误'
  249. ]);
  250. }
  251. try {
  252. $count = 0;
  253. foreach ($goods_id as $id) {
  254. $md_goods = MdGoods::find()->where(['goods_id' => $id])->all();
  255. if (empty($md_goods)) {
  256. continue;
  257. }
  258. $goods = Goods::findOne($id);
  259. foreach ($md_goods as $key => $value) {
  260. $value->attr = $goods->attr;
  261. $value->goods_num = $goods->goods_num;
  262. $value->price = $goods->price;
  263. $value->status = 0;
  264. if ($value->save()) {
  265. $count++;
  266. }
  267. }
  268. }
  269. return $this->asJson([
  270. 'code' => 0,
  271. 'msg' => '成功同步' . $count . '条门店商品数据',
  272. ]);
  273. } catch (\Exception $e) {
  274. return $this->asJson([
  275. 'code' => 0,
  276. 'msg' => '出现错误',
  277. ]);
  278. }
  279. }
  280. /**
  281. * 门店订单转单至平台
  282. */
  283. public function actionTransOrder()
  284. {
  285. $order_id = post_params('id');
  286. $order = Order::find()->where(['store_id' => get_store_id(), 'id' => $order_id, 'is_delete' => 0])->andWhere(
  287. ['<', 'trade_status', Order::ORDER_FLOW_CANCEL]
  288. )->one();
  289. if (!$order) {
  290. return $this->asJson([
  291. 'code' => 1,
  292. 'msg' => '转单数据有误'
  293. ]);
  294. }
  295. $order->is_trans = 1;
  296. if ($order->save()) {
  297. return $this->asJson([
  298. 'code' => 0,
  299. 'msg' => '转单成功'
  300. ]);
  301. } else {
  302. return $this->asJson([
  303. 'code' => 1,
  304. 'msg' => $order->errors[0]
  305. ]);
  306. }
  307. }
  308. /**
  309. * 更换店长
  310. * @return \yii\web\Response
  311. */
  312. public function actionManager()
  313. {
  314. $md_id = post_params('md_id');
  315. $saas_user_id = post_params('saas_user_id');
  316. if (empty($md_id) || empty($saas_user_id)) {
  317. return $this->asJson([
  318. 'code' => 1,
  319. 'msg' => '参数有误'
  320. ]);
  321. }
  322. $md = Md::findOne($md_id);
  323. if (!$md) {
  324. return $this->asJson([
  325. 'code' => 1,
  326. 'msg' => '门店不存在'
  327. ]);
  328. }
  329. $staff = MdStaff::findOne(['store_id' => get_store_id(), 'saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  330. $staff_1 = MdStaff::findOne(['store_id' => get_store_id(), 'md_id' => $md_id, 'saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  331. if ($staff && !$staff_1) {
  332. return $this->asJson([
  333. 'code' => 1,
  334. 'msg' => '该员工已在其他门店下,请重新选择'
  335. ]);
  336. }
  337. $t = \Yii::$app->db->beginTransaction();
  338. $old_manager = MdStaff::findOne(['store_id' => get_store_id(), 'md_id' => $md_id, 'is_manager' => 1, 'is_delete' => 0]);
  339. if ($old_manager) {
  340. $old_manager->is_manager = 0;
  341. if (!$old_manager->save()) {
  342. $t->rollBack();
  343. return $this->asJson([
  344. 'code' => 1,
  345. 'msg' => $old_manager->errors[0]
  346. ]);
  347. }
  348. }
  349. if (!$staff_1) {
  350. $saas_user = SaasUser::findOne($saas_user_id);
  351. $md_staff = new MdStaff();
  352. $md_staff->store_id = get_store_id();
  353. $md_staff->md_id = $md_id;
  354. $md_staff->saas_user_id = $saas_user_id;
  355. $md_staff->name = $saas_user->name;
  356. $md_staff->mobile = $saas_user->mobile;
  357. $md_staff->is_manager = 1;
  358. if (!$md_staff->save()) {
  359. $t->rollBack();
  360. return $this->asJson([
  361. 'code' => 1,
  362. 'msg' => $md_staff->errors[0]
  363. ]);
  364. }
  365. } else {
  366. $staff_1->is_manager = 1;
  367. if (!$staff_1->save()) {
  368. $t->rollBack();
  369. return $this->asJson([
  370. 'code' => 1,
  371. 'msg' => $staff_1->errors[0]
  372. ]);
  373. }
  374. }
  375. $md->manager = $saas_user_id;
  376. $md->user_id = $saas_user_id;
  377. if (!$md->save()) {
  378. $t->rollBack();
  379. return $this->asJson([
  380. 'code' => 1,
  381. 'data' => $md->errors[0]
  382. ]);
  383. }
  384. $t->commit();
  385. return $this->asJson([
  386. 'code' => 0,
  387. 'data' => '操作成功'
  388. ]);
  389. }
  390. /**
  391. * 批量操作
  392. * @return \yii\web\Response
  393. */
  394. public function actionBatch()
  395. {
  396. $id = post_params('id');
  397. $status = post_params('status');
  398. if (!is_array($id)) {
  399. return $this->asJson([
  400. 'code' => 1,
  401. 'msg' => '参数不正确'
  402. ]);
  403. }
  404. // 这里需要判断是否是独立运营门店 如果是独立运营门店 将独立运营门店修改为非独立的 并保留门店员工数据 如果是非独立运营门店执行删除 要删除门店员工
  405. $md_list = Md::find()->where(['in', 'id', $id])->all();
  406. foreach ($md_list as $md){
  407. if($md->is_single == 1){
  408. $md->is_single = 0;
  409. $md->save();
  410. }else{
  411. $md->is_delete = 1;
  412. if($md->save()){
  413. // 删除门店员工
  414. MdStaff::updateAll(['is_delete' => 1], ['id'=>$md->id]);
  415. }
  416. }
  417. }
  418. return $this->asJson([
  419. 'code' => 0,
  420. 'msg' => '更新成功'
  421. ]);
  422. }
  423. public function actionStaff()
  424. {
  425. $name = get_params('name');
  426. $mobile = get_params('mobile');
  427. $start_time = get_params('start_time');
  428. $end_time = get_params('end_time');
  429. $md_id = get_params('md_id');
  430. $store_id = get_store_id();
  431. $is_single = get_params('is_single');// 这里不能给默认值,给了的话会影响门店后台的员工列表请求
  432. if ($is_single == null) {
  433. $md = Md::findOne($md_id);
  434. if ($md) {
  435. $is_single = $md->is_single;
  436. }
  437. }
  438. $query = MdStaff::find()->alias('ms')->leftJoin(['md' => Md::tableName()], 'md.id=ms.md_id')->where(['ms.is_delete' => 0])->orderBy("ms.created_at desc, ms.updated_at desc");
  439. if ($md_id !== null) {
  440. if ($md_id <= 0) {
  441. $query->andWhere(['AND', ['ms.md_id' => [0, -1]], ['IS', 'md.id', NULL]]);
  442. } else {
  443. $query->andWhere(['ms.md_id' => $md_id, 'md.is_delete' => 0, 'md.is_single' =>$is_single]);
  444. }
  445. }else{
  446. // 商城后台查询员工的时候 要根据$is_single取独立运营门店 或者 非独立运营门店的店员
  447. $query->andWhere( ['md.is_single' =>$is_single]);
  448. }
  449. if ($store_id > 0) {
  450. $query->andWhere(['ms.store_id' => $store_id]);
  451. }
  452. if ($name) {
  453. $query->andWhere(['like', 'ms.name', $name]);
  454. }
  455. if ($mobile) {
  456. $query->andWhere(['like', 'ms.mobile', $mobile]);
  457. }
  458. if ($start_time) {
  459. $query->andWhere(['>=', 'ms.created_at', strtotime($start_time)]);
  460. }
  461. if ($end_time) {
  462. $query->andWhere(['<=', 'ms.created_at', strtotime($end_time)]);
  463. }
  464. $list = pagination_make($query);
  465. foreach ($list['list'] as &$val) {
  466. $saas_user = SaasUser::findOne($val['saas_user_id']);
  467. $user = User::findOne(['store_id' => get_store_id(),'binding' => $saas_user->mobile]);
  468. $val['avatar'] = $user->avatar_url;
  469. $val['md_name'] = Md::findOne($val['md_id'])->name;
  470. if ($val['md_id'] <= 0) {
  471. $val['md_name'] = Store::findOne($val['store_id'])->name;
  472. }
  473. $val['nickname'] = $user->nickname;
  474. }
  475. return $this->asJson([
  476. 'code' => 0,
  477. 'msg' => 'success',
  478. 'data' => [
  479. 'data' => $list['list'],
  480. 'pageNo' => $list['pageNo'],
  481. 'totalCount' => $list['totalCount']
  482. ]
  483. ]);
  484. }
  485. public function actionStaffAdd()
  486. {
  487. $store_id = get_store_id();
  488. $md_id = get_md_id();
  489. $name = post_params('name');
  490. $mobile = post_params('mobile');
  491. $saas_user_id = post_params('saas_user_id');
  492. if (empty($name) || empty($mobile) || empty($saas_user_id)) {
  493. return $this->asJson([
  494. 'code' => 1,
  495. 'msg' => '参数有误'
  496. ]);
  497. }
  498. $user = User::findOne($saas_user_id);
  499. if (!$user) {
  500. return $this->asJson([
  501. 'code' => 1,
  502. 'msg' => '用户不存在'
  503. ]);
  504. }
  505. $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
  506. if (!$saas_user) {
  507. return $this->asJson([
  508. 'code' => 1,
  509. 'msg' => '用户不存在'
  510. ]);
  511. }
  512. $staff = MdStaff::findOne(['store_id' => $store_id, 'saas_user_id' => $saas_user->id, 'is_delete' => 0]);
  513. if ($staff) {
  514. return $this->asJson([
  515. 'code' => 1,
  516. 'msg' => '该员工已在其他门店下,请重新绑定'
  517. ]);
  518. }
  519. if ($md_id <= 0) {
  520. $staff = MdStaff::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]);
  521. if ($staff) {
  522. return $this->asJson([
  523. 'code' => 1,
  524. 'msg' => '该用户已在其他店铺下,请重新绑定'
  525. ]);
  526. }
  527. }
  528. $md_staff = new MdStaff();
  529. $md_staff->store_id = $store_id;
  530. $md_staff->md_id = $md_id;
  531. $md_staff->saas_user_id = $saas_user->id;
  532. $md_staff->name = $name;
  533. $md_staff->mobile = $mobile;
  534. if (!$md_staff->save()) {
  535. return $this->asJson([
  536. 'code' => 1,
  537. 'msg' => $md_staff->errors[0]
  538. ]);
  539. }
  540. return $this->asJson([
  541. 'code' => 0,
  542. 'msg' => '保存成功'
  543. ]);
  544. }
  545. /**
  546. * 更新状态
  547. * @return \yii\web\Response
  548. */
  549. public function actionStaffStatus()
  550. {
  551. $id = post_params('id');
  552. $type = post_params('type');
  553. $status = post_params('status');
  554. if (empty($id) || !is_array($id)) {
  555. return $this->asJson([
  556. 'code' => 1,
  557. 'msg' => '参数有误'
  558. ]);
  559. }
  560. if (!in_array($status, [0, 1])) {
  561. return $this->asJson([
  562. 'code' => 1,
  563. 'msg' => '状态参数有误'
  564. ]);
  565. }
  566. if ($type == 'is_disable') {
  567. MdStaff::updateAll(['is_disable' => $status], ['in', 'id', $id]);
  568. }
  569. if ($type == 'is_delete') {
  570. MdStaff::updateAll(['is_delete' => $status], ['in', 'id', $id]);
  571. }
  572. return $this->asJson([
  573. 'code' => 0,
  574. 'msg' => '更新成功'
  575. ]);
  576. }
  577. public function actionSelectList()
  578. {
  579. $is_single = get_params('is_single', -1);
  580. $query = Md::find()->where(['is_delete' => 0, 'shop_audit' => 1, 'store_id' => get_store_id()])->select('id, name');
  581. if($is_single != -1){
  582. $query->andWhere(['is_single' => $is_single]);
  583. }
  584. $list = $query->asArray()->all();
  585. return $this->asJson(
  586. ['code' => 0, 'data' => $list]
  587. );
  588. }
  589. public function actionProfit()
  590. {
  591. $export = get_params('export');
  592. $order_no = get_params('order_no');
  593. $md_name = get_params('md_name');
  594. $is_send = get_params('is_send');
  595. $start_time = get_params('start_time');
  596. $end_time = get_params('end_time');
  597. $md_id = get_md_id();
  598. $query = MdProfit::find()->alias('mp')->leftJoin(['md' => Md::tableName()], 'md.id=mp.md_id')
  599. ->leftJoin(['o' => Order::tableName()], 'o.id=mp.order_id')
  600. ->where(['mp.store_id' => get_store_id()])
  601. ->select('mp.*, md.is_single, md.cover_url, o.order_no, o.user_id')->orderBy("mp.created_at desc, mp.updated_at desc");
  602. if ($md_id) {
  603. $query->andWhere(['mp.md_id' => $md_id]);
  604. }
  605. if (in_array($is_send, [0, 1])) {
  606. $query->andWhere(['mp.is_send' => $is_send]);
  607. }
  608. if ($order_no) {
  609. $query->andWhere(['like', 'o.order_no', $order_no]);
  610. }
  611. if ($md_name) {
  612. $query->andWhere(['like', 'md.name', $md_name]);
  613. }
  614. if ($start_time) {
  615. $query->andWhere(['>=', 'mp.created_at', strtotime($start_time)]);
  616. }
  617. if ($end_time) {
  618. $query->andWhere(['<=', 'mp.created_at', strtotime($end_time)]);
  619. }
  620. $list = pagination_make($query);
  621. foreach ($list['list'] as &$val) {
  622. $val['md_name'] = Md::findOne($val['md_id'])->name;
  623. if ($val['saas_user_id']) {
  624. $val['user_name'] = SaasUser::findOne($val['saas_user_id'])->name;
  625. } else {
  626. $val['user_name'] = SaasUser::findOne(['mobile' => User::findOne($val['user_id'])->binding])->name;
  627. }
  628. }
  629. if($export){
  630. return $this->exportProfit($list['list']);
  631. }
  632. return $this->asJson([
  633. 'code' => 0,
  634. 'msg' => 'success',
  635. 'data' => [
  636. 'data' => $list['list'],
  637. 'pageNo' => $list['pageNo'],
  638. 'totalCount' => $list['totalCount']
  639. ]
  640. ]);
  641. }
  642. private function exportProfit($list)
  643. {
  644. $rows = [[
  645. 'ID',
  646. '门店名称',
  647. '昵称',
  648. '下单时间',
  649. '订单号',
  650. '销售佣金(元)',
  651. '核销佣金(元)',
  652. '利润佣金(元)',
  653. '总佣金(元)',
  654. '操作时间',
  655. '佣金状态',
  656. ]];
  657. foreach($list as $item){
  658. $r = [
  659. $item['id'],
  660. $item['md_name'],
  661. $item['user_name'],
  662. date('Y-m-d H:i:s', $item['created_at']),
  663. $item['order_no'],
  664. $item['pay_profit'],
  665. $item['clerk_profit'],
  666. $item['sale_profit'],
  667. $item['total_profit'],
  668. $item['updated_at'] ? date('Y-m-d H:i:s', $item['updated_at']) : '-',
  669. $item['is_send'] == 0 ? '未到账' : '已到账',
  670. ];
  671. $rows[] = $r;
  672. }
  673. $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow()
  674. ->addRows($rows)->toBrowser();
  675. }
  676. public function actionProfitData()
  677. {
  678. $id = input_params('id');
  679. $store_id = get_store_id();
  680. $query = Md::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'shop_audit' => 1])->orderBy("id desc");
  681. $queryCount = clone $query;
  682. if ($id) {
  683. $query->andWhere(['id' => $id]);
  684. }
  685. $query->select('id, is_single, name, cover_url, total_profit, cash_profit');
  686. $list = pagination_make($query);
  687. foreach($list['list'] as &$item){
  688. $item['mdCashSum'] = floor_num(Cash::find()->where(['is_delete' => Cash::IS_DELETE_NO, 'md_id' => $item['id'], 'status' => 2])->andWhere(['cash_type' => 2])->sum('price'));
  689. $item['mdProfitWait'] = floor_num(MdProfit::find()->where(['md_id' => $item['id'], 'is_send' => 0])->sum('total_profit'));
  690. }
  691. if($list['pageNo'] == 1){
  692. $count = [];
  693. $count['mdCount'] = (int)$queryCount->count();
  694. $count['mdCashPriceSum'] = floor_num($queryCount->sum('cash_profit'));
  695. $count['mdCashSum'] = floor_num(Cash::find()->where(['is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id, 'status' => 2])->andWhere(['cash_type' => 2])->sum('price'));
  696. $count['mdProfitWait'] = floor_num(MdProfit::find()->where(['store_id' => $store_id, 'is_send' => 0])->sum('total_profit'));
  697. }
  698. return $this->asJson([
  699. 'code' => 0,
  700. 'msg' => 'success',
  701. 'data' => $list,
  702. 'count' => $count,
  703. ]);
  704. }
  705. public function actionOtherInfo()
  706. {
  707. // 获取门店设置
  708. $form = new MdSettingForm();
  709. $form->store_id = get_store_id();
  710. $result = $form->getSetting();
  711. return $this->asJson([
  712. 'code' => 0,
  713. 'data' => $result
  714. ]);
  715. }
  716. public function actionSubmitOtherInfo()
  717. {
  718. // 保存门店设置
  719. $form = new MdSettingForm();
  720. $form->store_id = get_store_id();
  721. $form->scenario = 'save';
  722. $form->attributes = all_params();
  723. $result = $form->saveSetting();
  724. return $this->asJson($result);
  725. }
  726. public function actionCashList()
  727. {
  728. $export = get_params('export');
  729. $md_id = get_params('md_id');
  730. $start_time = get_params('start_time');
  731. $end_time = get_params('end_time');
  732. $status = get_params('status');
  733. $type = get_params('type');
  734. $store_id = get_store_id();
  735. $query = Cash::find()->alias('c')
  736. ->leftJoin(['md' => Md::tableName()], 'md.id=c.md_id')
  737. ->where(['c.is_delete' => Cash::IS_DELETE_NO, 'c.store_id' => $store_id])
  738. ->andWhere(['c.cash_type' => 2]);
  739. if ($start_time) {
  740. $query->andWhere(['>=', 'c.created_at', strtotime($start_time)]);
  741. }
  742. if ($end_time) {
  743. $query->andWhere(['<=', 'c.created_at', strtotime($end_time)]);
  744. }
  745. if ($type != -1 && isset($type)) {
  746. $query->andWhere(['c.type' => $type]);
  747. }
  748. if ($md_id) {
  749. $query->andWhere(['c.md_id' => $md_id]);
  750. }
  751. if ($status == Cash::STATUS_APPLY) { //待审核
  752. $query->andWhere(['c.status' => Cash::STATUS_APPLY]);
  753. }
  754. if ($status == Cash::STATUS_CONFIRM) { // 待打款
  755. $query->andWhere(['c.status' => Cash::STATUS_CONFIRM]);
  756. }
  757. if ($status == Cash::STATUS_GIVEN) { // 已打款
  758. $query->andWhere(['in', 'c.status', [Cash::STATUS_GIVEN, Cash::STATUS_RECHARGE]]);
  759. }
  760. if ($status == Cash::STATUS_REFUSE) { // 已拒绝
  761. $query->andWhere(['c.status' => Cash::STATUS_REFUSE]);
  762. }
  763. $query->distinct()->orderBy('c.status ASC,c.created_at DESC')->select([
  764. 'c.*','md.name md_name', 'md.cover_url', 'md.is_single'
  765. ]);
  766. $pagination = pagination_make($query);
  767. $list = $pagination['list'];
  768. foreach($list as &$value){
  769. $value['service_money'] = $value['service_charge'] * $value['price'] / 100;
  770. $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  771. $value['updated_at'] = !empty($value['updated_at']) ? date('Y-m-d H:i:s', $value['updated_at']) : '';
  772. $value['money'] = Cash::getServiceMoney($value);
  773. $value['status_name'] = Cash::getCashStatusName($value);
  774. $saas_user = SaasUser::findOne(['mobile' => $value['binding']]);
  775. $value['avatar_url'] = !empty($saas_user['avatar']) ? $saas_user['avatar'] : $value['avatar_url'];
  776. $value['card_no'] = '';
  777. if (intval($value['type']) === Cash::TYPE_BANK) {
  778. if ($saas_user->withdraw_method) {
  779. $withdraw_method = json_decode($saas_user->withdraw_method, true);
  780. if (!empty($withdraw_method)) {
  781. foreach ($withdraw_method as $method_item) {
  782. if ($method_item['type'] === 'bank_card') {
  783. $value['card_no'] = $method_item['card_no'];
  784. }
  785. }
  786. }
  787. }
  788. }
  789. $value['type_text'] = Cash::getTypeName($value['type']) . "提现";
  790. }
  791. if($export){
  792. return $this->exportCashList($list);
  793. }
  794. $md = Md::findOne($md_id);
  795. $profit = [
  796. 'cash_profit' => '0.00',
  797. 'profit' => '0.00',
  798. 'total_profit' => '0.00',
  799. ];
  800. if ($md) {
  801. //可提现金额
  802. $profit['cash_profit'] = $md->cash_profit ?: '0.00';
  803. //已提现金额
  804. $saas_user_id = MdStaff::findOne(['store_id' => $store_id, 'md_id' => $md_id, 'is_manager' => 1])->saas_user_id;
  805. $profit['profit'] = Cash::find()->where(['user_id' => $saas_user_id, 'status' => [0, 1, 2],
  806. 'md_id' => $md_id, 'cash_type' => 2])->sum('price') ?: '0.00';
  807. //累计金额
  808. $profit['total_profit'] = $md->total_profit ?: '0.00';
  809. }
  810. return $this->asJson([
  811. 'code' => 0,
  812. 'msg' => 'success',
  813. 'data' => [
  814. 'data' => $list,
  815. 'profit' => $profit,
  816. 'pageNo' => $pagination['pageNo'],
  817. 'totalCount' => $pagination['totalCount']
  818. ],
  819. ]);
  820. }
  821. private function exportCashList($list)
  822. {
  823. $rows = [[
  824. 'ID',
  825. '提现方式',
  826. '提现金额(元)',
  827. '申请时间',
  828. '审批时间',
  829. '状态',
  830. ]];
  831. foreach($list as $item){
  832. $r = [
  833. $item['id'],
  834. $item['type'] == 0 ? '微信转账' : $item['type'] == 1 ? '支付宝转账' : '银行卡转账',
  835. $item['price'],
  836. date('Y-m-d H:i:s', $item['created_at']),
  837. $item['updated_at'] ? date('Y-m-d H:i:s', $item['updated_at']) : '-',
  838. $item['status'] == 0 ? '未处理' : $item['status'] == 1 ? '待打款' : $item['status'] == 2 ? '已完成' : $item['status'] == 3 ? '已拒绝' : '',
  839. ];
  840. $rows[] = $r;
  841. }
  842. $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow()
  843. ->addRows($rows)->toBrowser();
  844. }
  845. /**
  846. * 提现申请审核
  847. * @return \yii\web\Response
  848. */
  849. public function actionCashApply()
  850. {
  851. $id = post_params('id');
  852. $status = post_params('status');
  853. $store_id = get_store_id();
  854. if (empty($id) || !is_array($id)) {
  855. return $this->asJson([
  856. 'code' => 1,
  857. 'msg' => '数据格式错误'
  858. ]);
  859. }
  860. $t = \Yii::$app->db->beginTransaction();
  861. foreach ($id as $value) {
  862. $cash = Cash::findOne(['id' => $value, 'is_delete' => Cash::IS_DELETE_NO,
  863. 'store_id' => $store_id]);
  864. if (!$cash) {
  865. $t->rollBack();
  866. return $this->asJson([
  867. 'code' => 1,
  868. 'msg' => '提现记录不存在,请刷新重试'
  869. ]);
  870. }
  871. if (\in_array($cash->status, [1, 3])) {
  872. $t->rollBack();
  873. return $this->asJson([
  874. 'code' => 1,
  875. 'msg' => '操作失败,请刷新重试'
  876. ]);
  877. }
  878. if (!$cash->order_no) {
  879. $order_no = null;
  880. while (true) {
  881. $order_no = date('YmdHis') . mt_rand(100000, 999999);
  882. $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists();
  883. if (!$exist_order_no) {
  884. break;
  885. }
  886. }
  887. $cash->order_no = $order_no;
  888. $cash->save();
  889. }
  890. \Yii::$app->cache->set('md_cash_cache_' . $value, $cash->order_no);
  891. if (!in_array($status, [1, 3])) {
  892. \Yii::$app->cache->set('md_cash_cache_' . $value, false);
  893. $t->rollBack();
  894. return $this->asJson([
  895. 'code' => 1,
  896. 'msg' => '提现记录ID: ' . $value . '已审核,请刷新重试'
  897. ]);
  898. }
  899. $cash->status = $status;
  900. if ($status == Cash::STATUS_REFUSE) {
  901. $md = Md::findOne($cash->md_id);
  902. $md->updateCounters(['cash_profit' => $cash->price]);
  903. }
  904. if (!$cash->save()) {
  905. $t->rollBack();
  906. return $this->asJson([
  907. 'code' => 1,
  908. 'msg' => '网络异常,请刷新重试'
  909. ]);
  910. }
  911. }
  912. $t->commit();
  913. return $this->asJson([
  914. 'code' => 0,
  915. 'msg' => '审核成功'
  916. ]);
  917. }
  918. public function actionCashConfirm()
  919. {
  920. $id = post_params('id');
  921. $status = post_params('status');
  922. $store_id = get_store_id();
  923. $store = Store::findOne($store_id);
  924. $cash = Cash::findOne([
  925. 'id' => $id,
  926. 'is_delete' => Cash::IS_DELETE_NO,
  927. 'store_id' => $store_id
  928. ]);
  929. if (!$cash) {
  930. return $this->asJson([
  931. 'code' => 1,
  932. 'msg' => '提现记录不存在,请刷新重试'
  933. ]);
  934. }
  935. if ($status == Cash::STATUS_GIVEN) {
  936. if($store->is_platform_transfers == 1){
  937. $store_wechat_cash = json_decode(Option::get('store_wechat_cash', $store_id, 'store')['value'], true);
  938. $val = 0;
  939. foreach ((array)$store_wechat_cash as $value) {
  940. if (!empty($value)) {
  941. $val = 1;
  942. break;
  943. }
  944. }
  945. if(!$val){
  946. return $this->asJson([
  947. 'code' => 1,
  948. 'msg' => '未配置平台微信提现设置'
  949. ]);
  950. }
  951. }
  952. }
  953. if (!$cash->order_no) {
  954. $order_no = null;
  955. while (true) {
  956. $order_no = date('YmdHis') . mt_rand(100000, 999999);
  957. $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists();
  958. if (!$exist_order_no) {
  959. break;
  960. }
  961. }
  962. $cash->order_no = $order_no;
  963. $cash->save();
  964. }
  965. if ($cash->status != 1) {
  966. return $this->asJson([
  967. 'code' => 1,
  968. 'msg' => '操作错误,请刷新重试'
  969. ]);
  970. }
  971. $res = [];
  972. // $price = $cash->price;
  973. $price = Cash::getServiceMoney($cash);
  974. $servePrice = ($cash->price * ($cash->service_charge / 100));
  975. if ($store->store_balance < $price && $store->is_platform_transfers == 1) {
  976. return $this->asJson([
  977. 'code' => 1,
  978. 'msg' => '店铺剩余提现余额不足'
  979. ]);
  980. }
  981. $wechat_type = 1;
  982. $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value'];
  983. if($store->is_platform_transfers == 1){
  984. $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value'];
  985. $wechat_type = 0;
  986. }
  987. $t = \Yii::$app->db->beginTransaction();
  988. if ($status == Cash::STATUS_GIVEN) { //微信自动打款
  989. $cash->status = Cash::STATUS_GIVEN;
  990. $cash->pay_time = time();
  991. $cash->pay_type = Cash::PAY_TYPE_WX;
  992. $cash->wx_cash_status = -1;
  993. $user = User::findOne(['id' => $cash->user_id]);
  994. $data = [
  995. 'partner_trade_no' => $cash->order_no,
  996. 'openid' => $user->wechat_open_id,
  997. 'check_name' => 'NO_CHECK',
  998. 'amount' => $price * 100,
  999. 'desc' => '转账',
  1000. 'user_name' => $cash->name
  1001. ];
  1002. if ((int)$cash->type === 0) {
  1003. if (\Yii::$app->prod_is_dandianpu() && !\app\models\Store::hasIncoming($store_id)) {
  1004. //商城是否进件
  1005. //商城余额是否充足
  1006. $storeMoney = \app\models\StoreCash::getMaxCash($store);
  1007. if($storeMoney < $price){
  1008. $t->rollBack();
  1009. return $this->asJson([
  1010. 'code' => 1,
  1011. 'msg' => '操作错误,商城余额不足! 当前余额:¥' . $storeMoney
  1012. ]);
  1013. }
  1014. //扣除商城余额
  1015. $subMoney = \app\models\Store::subMoney($store, $price);
  1016. if(!$subMoney){
  1017. $t->rollBack();
  1018. return $this->asJson([
  1019. 'code' => 1,
  1020. 'msg' => '网络异常,subMoney失败1',
  1021. ]);
  1022. }
  1023. $cash->save();
  1024. $t->commit();
  1025. return $this->asJson([
  1026. 'code' => 0,
  1027. 'msg' => '成功'
  1028. ]);
  1029. } else {
  1030. if (\Yii::$app->prod_is_duli()) {
  1031. $WechatConfig = WechatConfig::findOne(['store_id' => get_store_id()]);
  1032. if (empty($WechatConfig->mch_id) || empty($WechatConfig->pay_key) || empty($WechatConfig->app_id)|| empty($WechatConfig->cert_pem)|| empty($WechatConfig->key_pem)) {
  1033. return $this->asJson([
  1034. 'code' => 1,
  1035. 'msg' => "后台参数配置错误,请检查参数后重试"
  1036. ]);
  1037. }
  1038. }
  1039. }
  1040. if ($wechat_type == 0) {
  1041. $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]);
  1042. $before = $store->store_balance;
  1043. $real_price = $cashExt ? $cashExt->real_price : $price;
  1044. $store->updateCounters(['store_balance' => -$real_price, 'price' => -$real_price, 'store_withdrawn_cash' => $real_price]);
  1045. $after = $store->store_balance;
  1046. $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice;
  1047. $cashExtPrice = $cashExt ? $cashExt->price : $cash->price;
  1048. $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price;
  1049. StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type);
  1050. }
  1051. $wechat = \Yii::$app->controller->wechatPay;
  1052. // $res = $wechat->transfer->toBalance($data);
  1053. $res = (new \app\utils\WechatMerchant\WxV3($wechat))->transferBatches(get_store_id(), $data);
  1054. //判断是否使用新版本转账 增加转账标识
  1055. $wechat_cash = json_decode($wechat_cash, true);
  1056. if (intval($wechat_cash['is_open']) === 2) {
  1057. if (!$res['code']) {
  1058. $cash->is_platform_transfers = intval($store->is_platform_transfers);
  1059. $cash->wx_cash_type = Cash::WX_CASH_TYPE_NEW;
  1060. $cash->wx_cash_state = $res['data']['state'];
  1061. $cash->wx_cash_result_info = json_encode($res['data'], JSON_UNESCAPED_UNICODE);
  1062. $cash->save();
  1063. }
  1064. }
  1065. NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '微信自动打款', ($cash->price - $price));
  1066. } elseif ((int)$cash->type === 1) {
  1067. $order = (object)[
  1068. 'store_id' => $cash->store_id,
  1069. 'order_no' => $cash->order_no,
  1070. 'pay_price' => sprintf("%.2f", $price),
  1071. 'name' => $cash->name
  1072. ];
  1073. $result = Alipay::transfer($order, $cash->mobile);
  1074. if (isset($result['code']) && $result['code'] == 1) {
  1075. if (strpos($result['msg'], 'aop.invalid-app-auth-token-no-api')) {
  1076. $result['msg'] = '接口未授权,请前往支付宝开放平台查询是否开通产品或授权支付宝转账产品';
  1077. }
  1078. if (strpos($result['msg'], 'PAYEE_NOT_EXIST')) {
  1079. $result['msg'] = '收款账号不存在或姓名有误,建议核实账号和姓名是否准确';
  1080. }
  1081. if (strpos($result['msg'], 'BALANCE_IS_NOT_ENOUGH')) {
  1082. $result['msg'] = '商户余额不足';
  1083. }
  1084. return $this->asJson($result);
  1085. } else {
  1086. // TODO 扣除店铺提现金额
  1087. if ($wechat_type == 0) {
  1088. $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]);
  1089. $before = $store->store_balance;
  1090. $real_price = $cashExt ? $cashExt->real_price : $price;
  1091. $store->updateCounters(['store_balance' => -$real_price, 'price' => -$real_price, 'store_withdrawn_cash' => $real_price]);
  1092. $after = $store->store_balance;
  1093. $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice;
  1094. $cashExtPrice = $cashExt ? $cashExt->price : $cash->price;
  1095. $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price;
  1096. StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type);
  1097. }
  1098. }
  1099. $cash->save();
  1100. $t->commit();
  1101. return $this->asJson([
  1102. 'code' => 0,
  1103. 'msg' => '成功'
  1104. ]);
  1105. }elseif ((int)$cash->type === 4) {
  1106. $user = User::findOne($cash->user_id);
  1107. $saas = SaasUser::findOne(['mobile' => $user->binding]);
  1108. $lg_info = Lg::find()->where(['user_id'=>$saas->id,'status'=>1,'is_delete'=>0])->one();
  1109. $lgApi = new LgApi($cash->store_id);
  1110. //灵工提现
  1111. $post_data = [
  1112. 'store_id' => $cash->store_id,
  1113. 'outTradeNo' => $cash->order_no,//唯一批次号
  1114. 'accNo' => bcmul($price,100),
  1115. 'amt' => bcmul($price,100),
  1116. 'name' => $lg_info->name,
  1117. 'certCard' => $lg_info->cert_card//身份证号
  1118. ];
  1119. $result = $lgApi->FlexiblePay($post_data);
  1120. if (isset($result['status']) && $result['status'] == 999) {
  1121. return $this->asJson($result);
  1122. }
  1123. $cash->status = 6;//灵工待打款
  1124. $cash->save();
  1125. $t->commit();
  1126. //灵工提现接口调用后消息队列查询状态
  1127. \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$store_id,'type'=>0,'retry' => 5]), 60);
  1128. return $this->asJson([
  1129. 'code' => 0,
  1130. 'msg' => '成功'
  1131. ]);
  1132. }
  1133. } elseif ($status == Cash::STATUS_HAND) { //手动打款
  1134. // TODO 扣除店铺提现金额
  1135. if ($wechat_type == 0) {
  1136. $before = $store->store_balance;
  1137. $store->updateCounters(['store_balance' => -$price, 'price' => -$price, 'store_withdrawn_cash' => $price]);
  1138. $after = $store->store_balance;
  1139. StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHOP, $price, " ID{$id}:用户提现{$cash->price}元,扣除手续费{$servePrice}元,提现实际扣除{$price}元", $before, $after, $wechat_type);
  1140. }
  1141. $cash->status = Cash::STATUS_GIVEN;
  1142. $cash->pay_time = time();
  1143. $cash->pay_type = Cash::PAY_TYPE_HAND;
  1144. $res['result_code'] = "SUCCESS";
  1145. // NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '手动打款', ($cash->price - $price));
  1146. }
  1147. if (isset($res['result_code']) && $res['result_code'] == 'SUCCESS') {
  1148. $cash->save();
  1149. if ($cash->cash_type == 2){
  1150. //灵工提现接口调用后消息队列查询状态
  1151. \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$store_id,'type'=>2,'retry' => 5]), 60);
  1152. }
  1153. if (intval($cash->type) === Cash::TYPE_RECHARGE) {
  1154. AccountLog::saveLog($cash->user_id, $price, 2, 1, 0, 0, '佣金提现打款');
  1155. }
  1156. $t->commit();
  1157. return $this->asJson([
  1158. 'code' => 0,
  1159. 'msg' => '成功'
  1160. ]);
  1161. } else {
  1162. $t->rollBack();
  1163. return $this->asJson([
  1164. 'code' => 1,
  1165. 'msg' => !empty($res['err_code_des']) ? $res['err_code_des'] : '请稍后重试',
  1166. 'data' => $res
  1167. ]);
  1168. }
  1169. }
  1170. public function actionCashSubmit()
  1171. {
  1172. $price = post_params('cash');
  1173. $type = post_params('type');
  1174. $name = post_params('name', '');
  1175. $account = post_params('account', '');
  1176. $bank = post_params('bank', '');
  1177. if (!$price || !in_array($type, [0, 1, 2])) {
  1178. return $this->asJson([
  1179. 'code' => 1,
  1180. 'msg' => '参数非法',
  1181. ]);
  1182. }
  1183. if (empty($name) || empty($account)) {
  1184. return $this->asJson([
  1185. 'code' => 1,
  1186. 'msg' => '账户和姓名不能为空',
  1187. ]);
  1188. }
  1189. if ($type == 2 && empty($bank)) {
  1190. return $this->asJson([
  1191. 'code' => 1,
  1192. 'msg' => '银行账号开户行不能为空',
  1193. ]);
  1194. }
  1195. $store_id = get_store_id();
  1196. $md_id = get_md_id();
  1197. $saas_user_id = MdStaff::findOne(['store_id' => $store_id, 'md_id' => $md_id, 'is_manager' => 1])->saas_user_id;
  1198. $md = Md::findOne($md_id);
  1199. if ($price > $md->cash_profit) {
  1200. return $this->asJson([
  1201. 'code' => 1,
  1202. 'msg' => '当前大于可提现金额'
  1203. ]);
  1204. }
  1205. $exit = Cash::find()->andWhere(['=', 'status', 0])->andWhere(['user_id' => $saas_user_id,
  1206. 'store_id' => $store_id, 'cash_type' => Cash::IS_CASH_TYPE_MD])->exists();
  1207. if ($exit) {
  1208. // return $this->asJson([
  1209. // 'code' => 1,
  1210. // 'msg' => '尚有未完成的提现申请'
  1211. // ]);
  1212. }
  1213. $saasUser = SaasUser::findOne($saas_user_id);
  1214. $user = User::find()->where(['store_id' => $store_id,'binding' => $saasUser->mobile,'is_delete' => 0])->one();
  1215. if(empty($user)){
  1216. return $this->asJson([
  1217. 'code' => 1,
  1218. 'msg' => '提现用户数据不能为空'
  1219. ]);
  1220. }
  1221. $t = \Yii::$app->db->beginTransaction();
  1222. $cash = new Cash();
  1223. $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_CASH);
  1224. $cash->is_delete = 0;
  1225. $cash->status = 0;
  1226. $cash->md_id = $md->id;
  1227. $cash->price = $price;
  1228. $cash->created_at = time();
  1229. $cash->user_id = $user->id;
  1230. $cash->store_id = $store_id;
  1231. $cash->type = $type;
  1232. $cash->name = $name;
  1233. $cash->mobile = $account;
  1234. $cash->bank_name = $bank;
  1235. $cash->pay_time = 0;
  1236. $cash->service_charge = 0;
  1237. $cash->cash_type = Cash::IS_CASH_TYPE_MD;
  1238. if ($cash->save()) {
  1239. $md->updateCounters(['cash_profit' => -$price]);
  1240. $t->commit();
  1241. return $this->asJson([
  1242. 'code' => 0,
  1243. 'msg' => '申请成功'
  1244. ]);
  1245. } else {
  1246. $t->rollBack();
  1247. return $this->asJson([
  1248. 'code' => 1,
  1249. 'msg' => '网络异常'
  1250. ]);
  1251. }
  1252. }
  1253. public function actionClerkOrderList()
  1254. {
  1255. $export = get_params('export');
  1256. $md_id = get_params('md_id');
  1257. $start_time = get_params('start_time');
  1258. $end_time = get_params('end_time');
  1259. $status = get_params('status');
  1260. $order_no = get_params('order_no');
  1261. $name = get_params('name');
  1262. $store_id = get_store_id();
  1263. $query = MdProfit::find()->alias('mp')->where(['mp.is_clerk' => 1, 'mp.store_id' => $store_id])
  1264. ->leftJoin(['ms' => MdStaff::tableName()], 'ms.id=mp.clerk_id')
  1265. ->leftJoin(['o' => Order::tableName()], 'o.id=mp.order_id');
  1266. if ($start_time) {
  1267. $query->andWhere(['>=', 'mp.created_at', strtotime($start_time)]);
  1268. }
  1269. if ($order_no) {
  1270. $query->andWhere(['like', 'o.order_no', $order_no]);
  1271. }
  1272. if ($name) {
  1273. $query->andWhere(['like', 'ms.name', $name]);
  1274. }
  1275. if ($end_time) {
  1276. $query->andWhere(['<=', 'mp.created_at', strtotime($end_time)]);
  1277. }
  1278. if ($md_id) {
  1279. $query->andWhere(['mp.md_id' => $md_id]);
  1280. }
  1281. if ($status != -1) {
  1282. $query->andWhere(['mp.is_send' => $status]);
  1283. }
  1284. $query->orderBy('mp.created_at desc, mp.updated_at desc')->select('mp.*, ms.name, o.order_no, o.pay_price');
  1285. $pagination = pagination_make($query);
  1286. $list = $pagination['list'];
  1287. foreach ($list as &$value) {
  1288. $value['goods_list'] = OrderDetail::find()->where(['order_id' => $value['order_id']])->select('goods_name, num, attr, pic, total_price')->asArray()->all();
  1289. }
  1290. if($export){
  1291. return $this->exportClerkOrderList($list);
  1292. }
  1293. return $this->asJson([
  1294. 'code' => 0,
  1295. 'msg' => 'success',
  1296. 'data' => [
  1297. 'data' => $list,
  1298. 'pageNo' => $pagination['pageNo'],
  1299. 'totalCount' => $pagination['totalCount']
  1300. ],
  1301. 'q' => $query->createCommand()->getRawSql(),
  1302. ]);
  1303. }
  1304. private function exportClerkOrderList($list)
  1305. {
  1306. $rows = [[
  1307. 'ID',
  1308. '订单编号',
  1309. '产品名称',
  1310. '规格',
  1311. '单价(元)',
  1312. '数量',
  1313. '订单金额(元)',
  1314. '核销员工',
  1315. '下单时间',
  1316. '核销时间',
  1317. '订单状态',
  1318. ]];
  1319. foreach($list as $item){
  1320. $r = [
  1321. $item['id'],
  1322. $item['order_no'],
  1323. $item['goods_list'][0]['goods_name'],
  1324. implode(',', array_column(json_decode($item['goods_list'][0]['attr'], true), 'attr_name')),
  1325. $item['goods_list'][0]['total_price'],
  1326. $item['goods_list'][0]['num'],
  1327. $item['pay_price'],
  1328. $item['name'],
  1329. date('Y-m-d H:i:s', $item['created_at']),
  1330. $item['updated_at'] ? date('Y-m-d H:i:s', $item['updated_at']) : '-',
  1331. $item['is_send'] == 0 ? '待核销':'已核销',
  1332. ];
  1333. $rows[] = $r;
  1334. if(count($item['goods_list']) > 1){
  1335. foreach($item['goods_list'] as $i => $goods){
  1336. if($i == 0) continue;
  1337. $r = [
  1338. '',
  1339. $item['goods_list'][$i]['goods_name'],
  1340. implode(',', array_column(json_decode($item['goods_list'][$i]['attr'], true), 'attr_name')),
  1341. $item['goods_list'][$i]['total_price'],
  1342. $item['goods_list'][$i]['num'],
  1343. ];
  1344. $rows[] = $r;
  1345. }
  1346. }
  1347. }
  1348. $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow()
  1349. ->addRows($rows)->toBrowser();
  1350. }
  1351. /**
  1352. * 门店团购活动列表
  1353. * @return \yii\web\Response
  1354. * @author: hankaige
  1355. * @Time: 2024/3/20 10:02
  1356. */
  1357. public function actionGroupActivities()
  1358. {
  1359. $form = new MdGroupActivitiesForm();
  1360. $form->store_id = get_store_id();
  1361. $form->attributes = get_params();
  1362. return $this->asJson($form->list());
  1363. }
  1364. /**
  1365. * 门店团购活动详情
  1366. * @return \yii\web\Response
  1367. * @author: hankaige
  1368. * @Time: 2024/3/20 10:02
  1369. */
  1370. public function actionGetGroupActivitiesItem()
  1371. {
  1372. $form = new MdGroupActivitiesForm();
  1373. $form->store_id = get_store_id();
  1374. $form->id = get_params('id');
  1375. return $this->asJson($form->item());
  1376. }
  1377. /**
  1378. * 设置门店团购活动
  1379. * @return \yii\web\Response
  1380. * @author: hankaige
  1381. * @Time: 2024/3/20 10:02
  1382. */
  1383. public function actionSaveGroupActivitiesItem()
  1384. {
  1385. $form = new MdGroupActivitiesForm();
  1386. $form->store_id = get_store_id();
  1387. $form->scenario = 'create';
  1388. $form->attributes = all_params();
  1389. return $this->asJson($form->createItem());
  1390. }
  1391. /**
  1392. * 删除门店团购活动
  1393. * @return \yii\web\Response
  1394. * @author: hankaige
  1395. * @Time: 2024/3/20 10:47
  1396. */
  1397. public function actionDelGroupActivitiesItem()
  1398. {
  1399. $form = new MdGroupActivitiesForm();
  1400. $form->store_id = get_store_id();
  1401. $form->ids = get_params('ids');
  1402. $form->scenario = 'del';
  1403. return $this->asJson($form->del());
  1404. }
  1405. public function actionGetQrcodeSetting()
  1406. {
  1407. //兼容联盟
  1408. $is_saas = get_params('is_saas',0);
  1409. if($is_saas){
  1410. $store_id = -1;
  1411. }else{
  1412. $store_id = get_store_id();
  1413. }
  1414. $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_MD]);
  1415. // \Yii::error($qrcode->font);
  1416. $color = Color::find()->select('id, color')->andWhere(['is_delete' => 0])->asArray()->all();
  1417. $font_position = json_decode($qrcode->font_position, true);
  1418. $qrcode_position = json_decode($qrcode->qrcode_position, true);
  1419. $avatar_position = json_decode($qrcode->avatar_position, true);
  1420. $avatar_size = json_decode($qrcode->avatar_size, true);
  1421. $qrcode_size = json_decode($qrcode->qrcode_size, true);
  1422. $font_size = json_decode($qrcode->font, true);
  1423. // \Yii::error($font_size);
  1424. $first = Color::findOne(['color' => $font_size['color']]);
  1425. $res = [
  1426. 'qrcode_bg' => $qrcode->qrcode_bg ?: \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/2_1.png',
  1427. 'qrcode_pic' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/1.png',
  1428. 'avatar' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png',
  1429. 'qrcode' => $qrcode,
  1430. 'color' => $color,
  1431. 'first' => $first->id,
  1432. 'font_c' => Json::decode($qrcode->font, true)['color'] ? Json::decode($qrcode->font, true)['color'] : ($first->color ?: "#000"),
  1433. 'avatar_w' => $avatar_size['w'] ?: '63',
  1434. 'avatar_x' => $avatar_position['x'] ?: '50',
  1435. 'avatar_y' => $avatar_position['y'] ?: '160',
  1436. 'qrcode_w' => $qrcode_size['w'] ?: '169',
  1437. 'qrcode_c' => empty($qrcode_size['c']) ? 1 : (($qrcode_size['c'] == "true") ? 1 : 0),
  1438. 'qrcode_x' => $qrcode_position['x'] ?: '65',
  1439. 'qrcode_y' => $qrcode_position['y'] ?: '240',
  1440. 'font_x' => $font_position['x'] ?: '124',
  1441. 'font_y' => $font_position['y'] ?: '180',
  1442. 'font_w' => $font_size['size'] ?: '20',
  1443. ];
  1444. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]);
  1445. }
  1446. /**
  1447. * 设置门店海报
  1448. * @return \yii\web\Response
  1449. * @author: hankaige
  1450. * @Time: 2024/3/25 10:36
  1451. */
  1452. public function actionSetQrcodeSetting()
  1453. {
  1454. $store_id = get_store_id();
  1455. //兼容联盟
  1456. $is_saas = post_params('is_saas',0);
  1457. if($is_saas){
  1458. $store_id = -1;
  1459. }
  1460. $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_MD]);
  1461. if (!$qrcode) {
  1462. $qrcode = new Qrcode();
  1463. }
  1464. $form = new QrcodeForm();
  1465. $form->attributes = post_params();
  1466. $form->store_id = $store_id;
  1467. $form->qrcode = $qrcode;
  1468. $form->type = Qrcode::TYPE_MD;
  1469. return $this->asJson($form->save());
  1470. }
  1471. /**
  1472. * 司机列表
  1473. * @return \yii\web\Response
  1474. * @author: hankaige
  1475. * @Time: 2024/3/22 15:57
  1476. */
  1477. public function actionDriverList()
  1478. {
  1479. $form = new MdGroupDriverForm();
  1480. $form->store_id = get_store_id();
  1481. $form->attributes = all_params();
  1482. return $this->asJson($form->getList());
  1483. }
  1484. /**
  1485. * 新增编辑司机
  1486. * @return \yii\web\Response
  1487. * @author: hankaige
  1488. * @Time: 2024/3/22 15:57
  1489. */
  1490. public function actionDriverSave()
  1491. {
  1492. $form = new MdGroupDriverForm();
  1493. $form->scenario = 'save';
  1494. $form->store_id = get_store_id();
  1495. $form->attributes = all_params();
  1496. return $this->asJson($form->createItem());
  1497. }
  1498. /**
  1499. * 删除司机
  1500. * @return \yii\web\Response
  1501. * @author: hankaige
  1502. * @Time: 2024/3/22 16:02
  1503. */
  1504. public function actionDriverDel()
  1505. {
  1506. $form = new MdGroupDriverForm();
  1507. $form->scenario = 'del';
  1508. $form->store_id = get_store_id();
  1509. $form->id = get_params('id');
  1510. return $this->asJson($form->delItem());
  1511. }
  1512. /**
  1513. * diy装修获取活动列表
  1514. * @return \yii\web\Response
  1515. * @author: hankaige
  1516. * @Time: 2024/3/25 11:47
  1517. */
  1518. public function actionGetActivities()
  1519. {
  1520. $form = new MdGroupActivitiesForm();
  1521. $form->store_id = get_store_id();
  1522. return $this->asJson($form->diyGetActivitiesList());
  1523. }
  1524. /**
  1525. * diy获取指定活动商品列表
  1526. * @return \yii\web\Response
  1527. * @author: hankaige
  1528. * @Time: 2024/3/25 11:47
  1529. */
  1530. public function actionGetActivityGoodsList()
  1531. {
  1532. $form = new MdGroupActivitiesForm();
  1533. $form->store_id = get_store_id();
  1534. $form->id = get_params('id');
  1535. return $this->asJson($form->getGoodsListByActivity());
  1536. }
  1537. /**
  1538. * 生成备货单操作
  1539. * @return \yii\web\Response
  1540. * @author: hankaige
  1541. * @Time: 2024/3/27 11:07
  1542. */
  1543. public function actionCreateInventory()
  1544. {
  1545. $form = new InventoryForm();
  1546. $form->store_id = get_store_id();
  1547. $form->attributes = all_params();
  1548. return $this->asJson($form->handleInventory());
  1549. }
  1550. /**
  1551. * 备货单列表
  1552. * @return \yii\web\Response
  1553. * @author: hankaige
  1554. * @Time: 2024/3/27 11:29
  1555. */
  1556. public function actionInventoryList()
  1557. {
  1558. $form = new InventoryForm();
  1559. $form->store_id = get_store_id();
  1560. return $this->asJson($form->getInventoryList());
  1561. }
  1562. /**
  1563. * 获取备货单详情
  1564. * @return \yii\web\Response
  1565. * @author: hankaige
  1566. * @Time: 2024/3/27 11:29
  1567. */
  1568. public function actionInventoryDetail()
  1569. {
  1570. $form = new InventoryForm();
  1571. $form->store_id = get_store_id();
  1572. $form->id = get_params('id');// 备货单ID
  1573. return $this->asJson($form->getInventoryDetail());
  1574. }
  1575. /**
  1576. * 分拣单列表
  1577. * @return \yii\web\Response
  1578. * @author: hankaige
  1579. * @Time: 2024/3/27 11:29
  1580. */
  1581. public function actionSortingList()
  1582. {
  1583. $form = new InventoryForm();
  1584. $form->store_id = get_store_id();
  1585. $form->md_id = get_params('md_id',0);// 根据门店搜索分拣单
  1586. $form->inventory_id = get_params('inventory_id',0);// 备货单iD
  1587. $form->status = get_params('status',-1);
  1588. $form->md_id = get_params('md_id',0);
  1589. return $this->asJson($form->getSortingList());
  1590. }
  1591. /**
  1592. * 获取分拣单详情
  1593. * @return \yii\web\Response
  1594. * @author: hankaige
  1595. * @Time: 2024/3/27 11:29
  1596. */
  1597. public function actionSortingDetail()
  1598. {
  1599. $form = new InventoryForm();
  1600. $form->store_id = get_store_id();
  1601. $form->id = get_params('id');// 分拣单ID
  1602. return $this->asJson($form->getSortingDetail());
  1603. }
  1604. /**
  1605. * 获取备货单的所有配送单
  1606. * @return \yii\web\Response
  1607. * @author: hankaige
  1608. * @Time: 2024/3/28 15:11
  1609. */
  1610. public function actionSortingDetailAll()
  1611. {
  1612. $form = new InventoryForm();
  1613. $form->store_id = get_store_id();
  1614. $form->id = get_params('id');// 备货单ID
  1615. return $this->asJson($form->getSortingDetailAll());
  1616. }
  1617. /**
  1618. * 获取可用司机列表
  1619. * @return \yii\web\Response
  1620. * @author: hankaige
  1621. * @Time: 2024/3/28 15:12
  1622. */
  1623. public function actionGetDriverList()
  1624. {
  1625. $form = new MdGroupDriverForm();
  1626. $form->store_id = get_store_id();
  1627. $form->keywords = get_params('keyword','');
  1628. $form->status = 1;
  1629. return $this->asJson($form->getList());
  1630. }
  1631. /**
  1632. * 配送单分配司机
  1633. * @return \yii\web\Response
  1634. * @author: hankaige
  1635. * @Time: 2024/3/28 15:12
  1636. */
  1637. public function actionSetDriver()
  1638. {
  1639. $form = new InventoryForm();
  1640. $form->store_id = get_store_id();
  1641. $form->driver_id = post_params('driver_id',0);
  1642. $form->sorting_id = post_params('sorting_id',[]);
  1643. return $this->asJson($form->setDriver());
  1644. }
  1645. /**
  1646. * 打印提货单信息
  1647. * @return \yii\web\Response
  1648. * @author: hankaige
  1649. * @Time: 2024/3/28 15:54
  1650. */
  1651. public function actionPrintTicket()
  1652. {
  1653. $form = new InventoryForm();
  1654. $form->store_id = get_store_id();
  1655. $form->inventory_id = get_params('id',0);
  1656. return $this->asJson($form->printTicket());
  1657. }
  1658. /**
  1659. * 获取自提门店选择列表
  1660. * @return \yii\web\Response
  1661. * @author: hankaige
  1662. * @Time: 2024/4/26 15:19
  1663. */
  1664. public function actionGetSelectShopList()
  1665. {
  1666. $query = Md::find()->where(['store_id'=>get_store_id(),'is_single'=>0,'is_delete' => 0])->select('id,name,cover_url');
  1667. $keyword = get_params('keyword','');
  1668. if(!empty($keyword)){
  1669. $query->andWhere(['like','name',$keyword]);
  1670. }
  1671. $result = pagination_make($query);
  1672. $result['data'] = $result['list'];
  1673. unset($result['list']);
  1674. return $this->asJson(['code'=>0,'data'=>$result,'msg'=>'数据获取成功']);
  1675. }
  1676. public function actionSetShopSingle()
  1677. {
  1678. $mdId = get_params('id');
  1679. $md = Md::findOne($mdId);
  1680. if(empty($md)){
  1681. return $this->asJson(['code'=>1,'data'=>[],'msg'=>'门店不存在']);
  1682. }
  1683. $md->is_single = 1;
  1684. if($md->save()){
  1685. return $this->asJson(['code'=>0,'data'=>[],'msg'=>'设置成功']);
  1686. }else{
  1687. return $this->asJson(['code'=>1,'data'=>[],'msg'=>'设置失败']);
  1688. }
  1689. }
  1690. //通过店铺获取门店列表
  1691. public function actionGetStoreMdList() {
  1692. $store_id = get_store_id();
  1693. $type = get_params('type', 0);//0获取所有门店 1排除绑定过仓库的门店
  1694. $field = "id, name";
  1695. $filter_md_id = [];
  1696. switch ($type) {
  1697. case 1:
  1698. $filter_md_id = AgentFrontBind::find()->where([
  1699. 'type' => AgentFrontBind::TYPE_STORE,
  1700. 'type_id' => $store_id,
  1701. 'is_delete' => 0,
  1702. 'status' => 1
  1703. ])->andWhere(['>', 'md_id', 0])->select('md_id')->column();
  1704. }
  1705. return $this->asJson([
  1706. 'code' => 0,
  1707. 'data' => MdForm::getMdList($store_id, $field, $filter_md_id),
  1708. 'msg' => '数据获取成功'
  1709. ]);
  1710. }
  1711. }