ShopController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use bizGhs\admin\classes\AdminClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizHd\admin\classes\ShopAdminClass;
  8. use bizHd\custom\classes\CustomClass as HdCustomClass;
  9. use bizHd\custom\classes\HdClass;
  10. use bizHd\merchant\classes\SjClass;
  11. use bizHd\merchant\services\ShopService;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use bizHd\saas\services\RegionService;
  14. use bizHd\shop\classes\ShopExtClass;
  15. use common\components\dict;
  16. use common\components\dirUtil;
  17. use common\components\imgUtil;
  18. use common\components\stringUtil;
  19. use common\components\util;
  20. use common\components\wxUtil;
  21. use Yii;
  22. class ShopController extends BaseController
  23. {
  24. public $guestAccess = ['all', 'gathering-img-url', 'check-shop'];
  25. public function actionModifySjName()
  26. {
  27. $get = Yii::$app->request->get();
  28. $adminId = $this->adminId;
  29. $staff = $this->shopAdmin;
  30. if ($staff->founder != 2 && $adminId != 4) {
  31. util::fail('老板才能改店名');
  32. }
  33. $name = $get['name'] ?? '';
  34. if (empty($name)) {
  35. util::fail('请填写名称');
  36. }
  37. //开启事务
  38. $connection = Yii::$app->db;
  39. $transaction = $connection->beginTransaction();
  40. try {
  41. $shop = $this->shop;
  42. $shop->merchantName = $name;
  43. $shop->save();
  44. $sj = SjClass::getById($shop->sjId, true);
  45. if (empty($sj)) {
  46. util::fail('门店信息缺失呢');
  47. }
  48. $sj->name = $name;
  49. $sj->save();
  50. $fullName = $shop->shopName == '首店' ? $name : $name . ' ' . $shop->shopName;
  51. $shopId = $shop->id;
  52. HdClass::updateByCondition(['shopId' => $shopId], ['name' => $fullName]);
  53. CustomClass::updateByCondition(['shopId' => $shopId], ['originName' => $fullName]);
  54. $transaction->commit();
  55. util::complete('修改成功');
  56. } catch (\Exception $exception) {
  57. $transaction->rollBack();
  58. Yii::error("修改门店名称失败:" . $exception->getMessage());
  59. util::fail('修改门店名称失败');
  60. }
  61. }
  62. //我的可以进入的门店 ssh 20230424
  63. public function actionMyShop()
  64. {
  65. $staff = $this->shopAdmin;
  66. $shopList = [];
  67. if (isset($staff->super) && $staff->super == 1) {
  68. $sjId = $this->sjId ?? 0;
  69. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'ptStyle' => 1], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id');
  70. }
  71. $adminId = $this->adminId ?? 0;
  72. $staffList = ShopAdminClass::getAllByCondition(['adminId' => $adminId], null, '*', null, true);
  73. $mainIdList = [];
  74. if (!empty($staffList)) {
  75. foreach ($staffList as $staff) {
  76. $isPt = $staff->isPt ?? 0;
  77. $delStatus = $staff->delStatus ?? 0;
  78. //$super = $staff->super ?? 0;
  79. $mainId = $staff->mainId ?? 0;
  80. if ($isPt == 0 && $delStatus == 0) {
  81. $mainIdList[] = $mainId;
  82. }
  83. }
  84. }
  85. if (!empty($mainIdList)) {
  86. $addShopList = ShopClass::getAllByCondition(['mainId' => ['in', $mainIdList], 'ptStyle' => 1], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id');
  87. if (!empty($addShopList)) {
  88. foreach ($addShopList as $addShop) {
  89. $addShopId = $addShop['id'] ?? 0;
  90. if (isset($shopList[$addShopId]) == false) {
  91. $shopList[$addShopId] = $addShop;
  92. }
  93. }
  94. }
  95. }
  96. $list = array_values($shopList);
  97. util::success(['list' => $list]);
  98. }
  99. //是否开启完整功能 ssh 20230226
  100. public function actionChangeOnlyCg()
  101. {
  102. $shop = $this->shop;
  103. $get = Yii::$app->request->get();
  104. $onlyCg = $get['onlyCg'] ?? 1;
  105. $shop->onlyCg = $onlyCg;
  106. $shop->save();
  107. util::complete('操作成功');
  108. }
  109. public function actionCheckShop()
  110. {
  111. $get = Yii::$app->request->get();
  112. $mobile = $get['mobile'] ?? '';
  113. if (empty($mobile)) {
  114. util::success(['has' => 0]);
  115. }
  116. $shop = ShopClass::getByCondition(['mobile' => $mobile], true);
  117. if (!empty($shop)) {
  118. util::success(['has' => 1]);
  119. }
  120. util::success(['has' => 0]);
  121. }
  122. //获取当前门店信息 ssh 2021.3.27
  123. public function actionCurrentShop()
  124. {
  125. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shop->id], false, false, 'reachVip');
  126. $shop = $this->shop->attributes;
  127. $shop['reachVip'] = $shopExt['reachVip'];
  128. //$shop['warning'] = '';
  129. $shop['warning'] = '明天凌晨1:00~2:00系统升级,暂停使用';
  130. util::success($shop);
  131. }
  132. //门店列表 ssh 20202.2.29
  133. public function actionList()
  134. {
  135. $where = [];
  136. $where['sjId'] = $this->sjId;
  137. $where['delStatus'] = 0;
  138. $list = \bizHd\shop\classes\ShopClass::getShopList($where);
  139. util::success($list);
  140. }
  141. //更新门店 ssh 2020.2.29
  142. public function actionUpdate()
  143. {
  144. $data = Yii::$app->request->post();
  145. $data['sjId'] = $this->sjId;
  146. $id = isset($data['id']) ? $data['id'] : 0;
  147. unset($data['id']);
  148. $data['meetNum'] = isset($data['meetNum']) ? intval($data['meetNum']) : 0;
  149. $data['meetAmount'] = isset($data['meetAmount']) ? floatval($data['meetAmount']) : 0;
  150. $data['cutAmount'] = isset($data['cutAmount']) ? floatval($data['cutAmount']) : 0;
  151. $shop = ShopService::getById($id);
  152. ShopClass::valid($shop, $this->sjId);
  153. $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
  154. //手机号具有唯一性,暂时不允许修改 --- 同批发端 app-ghs/controllers/ShopController.php 保持一致
  155. unset($data['mobile']);
  156. // 客服电话/微信二维码存 xhShopExt,不能混入主表更新
  157. $serviceMobile = isset($data['serviceMobile']) ? trim((string)$data['serviceMobile']) : '';
  158. $serviceWx = isset($data['serviceWx']) ? trim((string)$data['serviceWx']) : '';
  159. unset($data['serviceMobile'], $data['serviceWx']);
  160. // 添加事务处理
  161. $connection = Yii::$app->db;
  162. $transaction = $connection->beginTransaction();
  163. try {
  164. ShopClass::updateShop($shop, $data);
  165. // 老门店可能没有 ext 记录:有则更新,无则补建
  166. $ext = ShopExtClass::getByCondition(['shopId' => $id], true);
  167. if (!empty($ext)) {
  168. ShopExtClass::updateByCondition(['shopId' => $id], [
  169. 'serviceMobile' => $serviceMobile,
  170. 'serviceWx' => $serviceWx,
  171. ]);
  172. } else {
  173. ShopExtClass::add([
  174. 'shopId' => $id,
  175. 'serviceMobile' => $serviceMobile,
  176. 'serviceWx' => $serviceWx,
  177. ]);
  178. }
  179. $transaction->commit();
  180. util::complete();
  181. } catch (\Exception $exception) {
  182. $transaction->rollBack();
  183. Yii::error("更新门店失败:" . $exception->getMessage());
  184. util::fail('更新门店失败');
  185. }
  186. }
  187. //修改门店营业时间
  188. public function actionUpdateOpenTime()
  189. {
  190. $post = Yii::$app->request->post();
  191. $shopId = intval($post['shopId'] ?? $post['id'] ?? 0);
  192. if ($shopId <= 0) {
  193. $shopId = intval($this->shopId);
  194. }
  195. if ($shopId != intval($this->shopId)) {
  196. util::fail('不是您的门店');
  197. }
  198. $shop = ShopClass::getShopInfo($shopId);
  199. if (empty($shop)) {
  200. util::fail('门店不存在');
  201. }
  202. ShopClass::valid($shop, $this->sjId);
  203. ShopClass::updateOpenTime($shop, $post);
  204. util::complete('修改成功');
  205. }
  206. public function actionAdd()
  207. {
  208. $data = Yii::$app->request->post();
  209. $data['sjId'] = $this->sjId;
  210. $data['shopId'] = $this->shopId;
  211. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  212. util::fail('请填写门店名称');
  213. }
  214. $sj = $this->sj;
  215. $sjName = $sj->name ?? '';
  216. $data['merchantName'] = $sjName;
  217. $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
  218. $data['ptStyle'] = $ptStyle;
  219. $connection = Yii::$app->db;
  220. $transaction = $connection->beginTransaction();
  221. try {
  222. $mobile = $data['mobile'] ?? 0;
  223. if (stringUtil::isMobile($mobile) == false) {
  224. util::fail('请填写正确手机号');
  225. }
  226. $adminInfo = ['name' => $mobile, 'mobile' => $mobile];
  227. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  228. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  229. $adminId = $admin['id'] ?? 0;
  230. $data['adminId'] = $adminId;
  231. \bizHd\shop\classes\ShopClass::addMainShop($data, $this->shop, $this->sj);
  232. $transaction->commit();
  233. util::complete();
  234. } catch (\Exception $exception) {
  235. $transaction->rollBack();
  236. util::fail();
  237. }
  238. }
  239. //切换门店 lqh 2021.1.31
  240. public function actionToggleShop()
  241. {
  242. $adminId = $this->adminId;
  243. $mainId = $this->mainId;
  244. //多处要同步修改,关键词 no_allow_toggle_shop
  245. if (getenv('YII_ENV') == 'production') {
  246. //安海恋善不允许切换门店
  247. if (in_array($mainId, [44759, 56314, 56315, 56452])) {
  248. if (in_array($adminId, [54630, 54723])) {
  249. util::fail('专用账号,不允许切换门店');
  250. }
  251. }
  252. //惠雅南城不允许切换门店
  253. if ($mainId == 52 && $adminId == 3539) {
  254. util::fail('收银专用账号,不允许切换门店');
  255. }
  256. //惠雅莞城不允许切换门店
  257. if ($mainId == 1459 && $adminId == 2812) {
  258. util::fail('收银专用账号,不允许切换门店');
  259. }
  260. //淘花里中山店
  261. if ($mainId == 16948 && $adminId == 17908) {
  262. util::fail('收银专用账号,不允许切换门店');
  263. }
  264. //淘花里小榄店
  265. if ($mainId == 72057 && $adminId == 69792) {
  266. util::fail('收银专用账号,不允许切换门店');
  267. }
  268. }
  269. $shopAdmin = $this->shopAdmin;
  270. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  271. if ($switchShop == 0) {
  272. util::fail('不能切换门店');
  273. }
  274. $newShopId = Yii::$app->request->post('shopId', 0);
  275. $deviceId = Yii::$app->request->post('deviceId', '');
  276. $newShop = ShopClass::getById($newShopId, true);
  277. if (empty($newShop)) {
  278. util::fail('没有找到门店30');
  279. }
  280. $res = \bizHd\admin\classes\AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  281. if ($deviceId != '') {
  282. //设备登录状态更新
  283. $oldDevice = \bizHd\device\classes\HdDeviceClass::getByCondition(['shopId' => $this->shopId, 'deviceId' => $deviceId], true);
  284. if ($oldDevice) {
  285. $oldDevice->status = 0;
  286. $oldDevice->save();
  287. }
  288. $newLoginDevice = \bizHd\device\classes\HdDeviceClass::getByCondition(['shopId' => $newShopId, 'deviceId' => $deviceId], true);
  289. if ($newLoginDevice) {
  290. $newLoginDevice->status = 1;
  291. $newLoginDevice->save();
  292. }
  293. }
  294. util::success($res);
  295. }
  296. //网页端使用,下载微信和支付宝收款码 ssh 20250821
  297. public function actionGatheringCode()
  298. {
  299. $id = Yii::$app->request->get('id', 0);
  300. $shop = ShopService::getById($id, true);
  301. if (empty($shop)) {
  302. util::fail('没有找到门店31');
  303. }
  304. ShopClass::valid($shop->attributes, $this->sjId);
  305. $imgUrl = ShopClass::generateGatheringCode($this->sjId, $id);
  306. $shopName = $shop->shopName ?? '';
  307. $file = fopen($imgUrl, "rb");
  308. Header("Content-type: application/octet-stream ");
  309. Header("Accept-Ranges: bytes ");
  310. Header("Content-Disposition: attachment;filename={$shopName}收款码.jpg");
  311. $contents = "";
  312. while (!feof($file)) {
  313. $contents .= fread($file, 8192);
  314. }
  315. echo $contents;
  316. fclose($file);
  317. }
  318. //小程序端使用,下载收款码 ssh 20250821
  319. public function actionMiniGatheringCode()
  320. {
  321. $shop = $this->shop;
  322. $shopId = $shop->id;
  323. $imgUrl = ShopClass::generateGatheringCode($this->sjId, $shopId);
  324. util::success(['imgUrl' => $imgUrl]);
  325. }
  326. //获取二维码
  327. public function actionGetGatheringCodeUrl()
  328. {
  329. $id = Yii::$app->request->get('id', 0);
  330. $shop = ShopService::getById($id, true);
  331. if (empty($shop)) {
  332. util::fail('没有找到门店32');
  333. }
  334. ShopClass::valid($shop->attributes, $this->sjId);
  335. $imgUrl = Yii::$app->params['hdHost'] . '/auth/gathering-img-url?id=' . $id;
  336. util::success(['url' => $imgUrl]);
  337. }
  338. public function actionGatheringImgUrl()
  339. {
  340. $id = Yii::$app->request->get('id', 0);
  341. $shop = ShopService::getById($id, true);
  342. if (empty($shop)) {
  343. util::fail('没有找到门店33');
  344. }
  345. $sjId = $shop->sjId;
  346. $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
  347. $fileResource = file_get_contents($imgUrl);
  348. header('Content-type: image/jpeg');
  349. echo $fileResource;
  350. }
  351. //获取小程序的收款码 ssh
  352. public function actionGatheringMiniCode()
  353. {
  354. $id = Yii::$app->request->get('id', 0);
  355. $extend = MerchantExtendService::getBySjId($this->sjId);
  356. if ($extend['miniAuth'] == 0) {
  357. util::fail('您的小程序还没有授权');
  358. }
  359. $shop = ShopService::getById($id);
  360. ShopService::valid($shop, $this->sjId);
  361. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  362. $file = dirUtil::getImgDir() . $applyMemberCode;
  363. if (file_exists($file) == false) {
  364. util::fail('没有找到注册会员码');
  365. }
  366. $fileName = "门店({$id})小程序收款码.jpg";
  367. $contentType = 'image/jpeg';
  368. header("Cache-control: private");
  369. header("Content-type: $contentType"); //设置要下载的文件类型
  370. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  371. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  372. readfile($file);
  373. }
  374. //下载会员注册码 ssh 2020.2.29
  375. public function actionApplyMemberCode()
  376. {
  377. $id = Yii::$app->request->get('id', 0);
  378. $extend = MerchantExtendService::getBySjId($this->sjId);
  379. if ($extend['miniAuth'] == 0) {
  380. util::fail('您的小程序还没有授权');
  381. }
  382. $shop = ShopService::getById($id);
  383. ShopService::valid($shop, $this->sjId);
  384. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  385. $file = dirUtil::getImgDir() . $applyMemberCode;
  386. if (file_exists($file) == false) {
  387. util::fail('没有找到注册会员码');
  388. }
  389. $fileName = "注册会员码{$id}.jpg";
  390. $contentType = 'image/jpeg';
  391. header("Cache-control: private");
  392. header("Content-type: $contentType"); //设置要下载的文件类型
  393. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  394. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  395. readfile($file);
  396. }
  397. //删除门店 ssh 2020.3.1
  398. public function actionDelete()
  399. {
  400. util::fail('禁止操作');
  401. $id = Yii::$app->request->get('id', 0);
  402. util::fail('功能开发中');
  403. $shop = ShopService::getById($id);
  404. ShopService::valid($shop, $this->sjId);
  405. ShopService::deleteShop($shop);
  406. util::complete();
  407. }
  408. //获取门店详情 ssh 2021.4.23
  409. public function actionDetail()
  410. {
  411. $shopId = Yii::$app->request->get('shopId');
  412. if (empty($shopId)) {
  413. $shopId = $this->shopId;
  414. }
  415. $shop = ShopClass::getShopInfo($shopId);
  416. $shop['hasMap'] = dict::getDict('hasMap'); //添加 hasMap 属性(字典中的 hasMap)
  417. // 合并 xhShopExt 客服电话/微信二维码,供门店编辑页回填
  418. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  419. $shortServiceWx = !empty($ext) ? ($ext->serviceWx ?? '') : '';
  420. $shop['serviceMobile'] = !empty($ext) ? ($ext->serviceMobile ?? '') : '';
  421. $shop['shortServiceWx'] = $shortServiceWx;
  422. $shop['serviceWx'] = empty($shortServiceWx)
  423. ? ''
  424. : imgUtil::groupImg($shortServiceWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  425. util::success(['info' => $shop]);
  426. }
  427. //提现信息更新 ssh 2021.3.23
  428. public function actionCashUpdate()
  429. {
  430. $get = Yii::$app->request->get();
  431. $cashAccount = $get['cashAccount'] ?? '';
  432. $cashName = $get['cashName'] ?? '';
  433. $cashBank = $get['cashBank'] ?? '';
  434. if (empty($cashName)) {
  435. util::fail('请填写姓名');
  436. }
  437. if (empty($cashAccount)) {
  438. util::fail('请填写银行卡号');
  439. }
  440. if (empty($cashBank)) {
  441. util::fail('请输入开户行');
  442. }
  443. $shopAdmin = $this->shopAdmin;
  444. $shopId = $shopAdmin->shopId ?? 0;
  445. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  446. util::fail('超管才能操作');
  447. }
  448. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  449. $shop = $this->shop;
  450. $sjName = $shop->merchantName ?? '';
  451. $shopName = $shop->shopName ?? '';
  452. //noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347');
  453. util::complete();
  454. }
  455. //获取所有门店lqh 2021.1.31
  456. public function actionAll()
  457. {
  458. $res = [];
  459. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  460. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  461. $res = ShopClass::getAllShop($this->sjId);
  462. }
  463. util::success($res);
  464. }
  465. //获取采购时的支付方式 ssh 20211004
  466. public function actionGetCgPayWay()
  467. {
  468. $get = Yii::$app->request->get();
  469. $id = $get['id'] ?? 0;
  470. $cg = PurchaseClass::getById($id, true);
  471. PurchaseClass::valid($cg, $this->shopId);
  472. $customId = $cg->customId ?? 0;
  473. $custom = CustomClass::getById($customId);
  474. $hasDebtPay = $custom['debt'] ?? 0;
  475. //预订单不能欠款
  476. if ($cg->book == 1) {
  477. $hasDebtPay = 0;
  478. }
  479. $current = time();
  480. $cgDeadTime = strtotime($cg->deadline);
  481. //让客户在失效前$aheadTime秒要支付,这样回调通知时订单才不会过期状态
  482. $aheadTime = dict::getDict('order_online_pay_has_ahead_time');
  483. $count = $cgDeadTime - $current - $aheadTime;
  484. $data = [];
  485. $data['balance'] = $this->shop->balance ?? 0;
  486. $data['count'] = $count;
  487. $data['hasDebtPay'] = $hasDebtPay;
  488. util::success($data);
  489. }
  490. //地区 ssh 20220606
  491. public function actionRegion()
  492. {
  493. $regionTree = RegionService::tree();
  494. util::success(['region' => $regionTree]);
  495. }
  496. //散客门店详情 ssh 20211007
  497. public function actionKjCustom()
  498. {
  499. $defaultCustomId = $this->shop->defaultCustomId ?? 0;
  500. $custom = [];
  501. if (!empty($defaultCustomId)) {
  502. $custom = HdCustomClass::getById($defaultCustomId);
  503. $avatar = $custom['avatar'] ?? '';
  504. $custom['avatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  505. }
  506. util::success(['custom' => $custom]);
  507. }
  508. //散客门店设置
  509. public function actionKjCustomSet()
  510. {
  511. $id = Yii::$app->request->get('id', 0);
  512. $custom = HdCustomClass::getById($id, true);
  513. if (empty($custom)) {
  514. util::fail('没有找到客户');
  515. }
  516. if ($custom->shopId != $this->shopId) {
  517. util::fail('客户不属于当前门店');
  518. }
  519. $shop = $this->shop;
  520. $shop->defaultCustomId = $id;
  521. $shop->save();
  522. util::complete('修改成功');
  523. }
  524. public function actionUpdateShopAvatar()
  525. {
  526. $data = Yii::$app->request->post();
  527. $id = isset($data['id']) ? $data['id'] : 0;
  528. $shop = ShopClass::getById($id, true, 'id, sjId, avatar');
  529. ShopService::valid($shop, $this->sjId);
  530. if (isset($data['avatar']) && $data['avatar'] != '') {
  531. $shop->avatar = $data['avatar'];
  532. $re = $shop->save();
  533. if ($re) {
  534. \bizGhs\custom\classes\CustomClass::updateByCondition(['shopId' => $id], [
  535. 'avatar' => $data['avatar']
  536. ]);
  537. util::complete('头像修改完成');
  538. }
  539. util::fail('头像修改失败');
  540. }
  541. util::fail('头像参数出错');
  542. }
  543. //获取充值设置
  544. public function actionGetRechargeSetting()
  545. {
  546. $shopId = $this->shop->id;
  547. $shop = ShopClass::getById($shopId, false, 'rechargeWeal');
  548. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'reachVip');
  549. $return = [
  550. 'rechargeRule' => $shop['rechargeWeal'] == 3 ? 2 : $shop['rechargeWeal'],
  551. 'isVipMember' => $shopExt['reachVip'] > 0 ? 1 : 0,
  552. 'vipAmount' => $shopExt['reachVip'],
  553. 'hbPayable' => $shop['rechargeWeal'] == 2 ? 1 : 0,
  554. ];
  555. util::success($return);
  556. }
  557. //充值设置
  558. public function actionSaveRechargeSetting()
  559. {
  560. $data = Yii::$app->request->post();
  561. $rechargeWeal = intval($data['rechargeRule']);
  562. $isVipMember = intval($data['isVipMember']);
  563. if ($isVipMember == 1 && $data['vipAmount'] >= 0.01) {
  564. $reachVip = floatval($data['vipAmount']);
  565. } else {
  566. $reachVip = 0;
  567. }
  568. $hbPayable = intval($data['hbPayable']);
  569. if ($rechargeWeal == 2 && $hbPayable == 0) {
  570. $rechargeWeal = 3;
  571. }
  572. $shopAdmin = $this->shopAdmin;
  573. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  574. util::fail('超管才能操作');
  575. }
  576. $shopId = $this->shop->id;
  577. ShopClass::updateById($shopId, ['rechargeWeal' => $rechargeWeal]);
  578. ShopExtClass::updateByCondition(['shopId' => $shopId], ['reachVip' => $reachVip]);
  579. util::complete('充值设置成功');
  580. }
  581. }