ShopController.php 23 KB

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