ShopController.php 24 KB

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