ShopController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\MainClass;
  4. use biz\shop\classes\ShopAdminClass;
  5. use biz\sj\services\MerchantExtendService;
  6. use bizGhs\admin\classes\AdminClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\merchant\classes\ShopClass;
  9. use bizGhs\merchant\services\ShopService;
  10. use bizHd\saas\services\RegionService;
  11. use common\components\dict;
  12. use common\components\dirUtil;
  13. use common\components\httpUtil;
  14. use common\components\imgUtil;
  15. use common\components\stringUtil;
  16. use common\components\util;
  17. use common\components\wxUtil;
  18. use Yii;
  19. class ShopController extends BaseController
  20. {
  21. public $guestAccess = ['all'];
  22. //绑定零售店 ssh 20220430
  23. public function actionBindLsShop()
  24. {
  25. $id = Yii::$app->request->get('id');
  26. $connection = Yii::$app->db;
  27. $transaction = $connection->beginTransaction();
  28. util::fail('此方法已停用,如需启用请确认有没问题');
  29. try {
  30. $shop = $this->shop ?? [];
  31. $lsShopId = $shop->lsShopId ?? 0;
  32. if (!empty($lsShopId)) {
  33. util::fail('您已经绑定过了');
  34. }
  35. ShopClass::bindLsShopByCustomId($shop, $id, $this->adminId);
  36. $transaction->commit();
  37. util::complete();
  38. } catch (\Exception $exception) {
  39. $transaction->rollBack();
  40. util::fail('绑定失败');
  41. }
  42. }
  43. //预订设置 ssh 20220324
  44. public function actionBookSet()
  45. {
  46. $get = Yii::$app->request->get();
  47. $kiloFee = $get['kiloFee'] ?? 0;
  48. $miniKilo = $get['miniKilo'] ?? 0;
  49. $this->shop->kiloFee = $kiloFee;
  50. $this->shop->miniKilo = $miniKilo;
  51. $this->shop->save();
  52. util::complete();
  53. }
  54. //当前门店信息
  55. public function actionInfo()
  56. {
  57. $shop = $this->shop ?? [];
  58. util::success($shop);
  59. }
  60. //获取当前门店信息 ssh 2021.3.27
  61. public function actionCurrentShop()
  62. {
  63. $main = $this->shop;
  64. util::success($main);
  65. }
  66. //门店列表 ssh 2021.1.14
  67. public function actionList()
  68. {
  69. $where = [];
  70. $where['sjId'] = $this->sjId;
  71. $where['delStatus'] = 0;
  72. $list = ShopClass::getShopList($where);
  73. util::success($list);
  74. }
  75. //更新门店 ssh 2020.2.29
  76. public function actionUpdate()
  77. {
  78. $shop = $this->shop;
  79. $join = $shop->join ?? 0;
  80. $default = $shop->default ?? 0;
  81. if ($join == 0 && $default == 0) {
  82. util::fail('请在总店操作');
  83. }
  84. $data = Yii::$app->request->post();
  85. $data['sjId'] = $this->sjId;
  86. $id = $data['id'] ?? 0;
  87. $shop = ShopService::getById($id);
  88. if (empty($shop)) {
  89. util::fail('没有找到门店');
  90. }
  91. ShopClass::valid($shop, $this->sjId);
  92. $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
  93. \biz\shop\classes\ShopClass::updateShop($shop, $data);
  94. util::complete();
  95. }
  96. //添加门店 ssh 2021.1.14
  97. public function actionAdd()
  98. {
  99. $shop = $this->shop;
  100. $join = $shop->join ?? 0;
  101. $default = $shop->default ?? 0;
  102. if ($join == 0 && $default == 0) {
  103. util::fail('请在总店操作');
  104. }
  105. $data = Yii::$app->request->post();
  106. $data['sjId'] = $this->sjId;
  107. $data['shopId'] = $this->shopId;
  108. $data['adminId'] = $this->adminId;
  109. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  110. util::fail('请填写门店名称');
  111. }
  112. $sj = $this->sj;
  113. $sjName = $sj->name ?? '';
  114. $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
  115. $data['ptStyle'] = $ptStyle;
  116. $data['merchantName'] = $sjName;
  117. $connection = Yii::$app->db;
  118. $transaction = $connection->beginTransaction();
  119. try {
  120. $mobile = $data['mobile'] ?? 0;
  121. if (stringUtil::isMobile($mobile) == false) {
  122. util::fail('请填写正确手机号');
  123. }
  124. $adminInfo = ['name' => $mobile, 'mobile' => $mobile];
  125. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  126. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  127. $adminId = $admin['id'] ?? 0;
  128. $data['adminId'] = $adminId;
  129. ShopClass::addMainShop($data, $this->shop, $this->sj);
  130. $transaction->commit();
  131. util::complete();
  132. } catch (\Exception $exception) {
  133. $transaction->rollBack();
  134. util::fail();
  135. }
  136. }
  137. //PC下载微信和支付宝收款码 ssh 2020.2.29
  138. public function actionGatheringCode()
  139. {
  140. $id = Yii::$app->request->get('id', 0);
  141. $shop = ShopService::getById($id);
  142. ShopClass::valid($shop, $this->sjId);
  143. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  144. $file = dirUtil::getImgDir() . $gatheringCode;
  145. if (file_exists($file) == false) {
  146. util::fail('没有找到收款码');
  147. }
  148. if (httpUtil::isMiniProgram()) {
  149. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  150. util::success(['imgUrl' => $imgUrl]);
  151. }
  152. $fileName = "门店({$id})收款码.jpg";
  153. $contentType = 'image/jpeg';
  154. header("Cache-control: private");
  155. header("Content-type: $contentType"); //设置要下载的文件类型
  156. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  157. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  158. readfile($file);
  159. }
  160. //PC获取小程序的收款码 ssh
  161. public function actionGatheringMiniCode()
  162. {
  163. $id = Yii::$app->request->get('id', 0);
  164. $extend = MerchantExtendService::getBySjId($this->sjId);
  165. if ($extend['miniAuth'] == 0) {
  166. util::fail('您的小程序还没有授权');
  167. }
  168. $shop = ShopService::getById($id);
  169. ShopClass::valid($shop, $this->sjId);
  170. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  171. $file = dirUtil::getImgDir() . $applyMemberCode;
  172. if (file_exists($file) == false) {
  173. util::fail('没有找到注册会员码');
  174. }
  175. if (httpUtil::isMiniProgram()) {
  176. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  177. util::success(['imgUrl' => $imgUrl]);
  178. }
  179. $fileName = "门店({$id})小程序收款码.jpg";
  180. $contentType = 'image/jpeg';
  181. header("Cache-control: private");
  182. header("Content-type: $contentType"); //设置要下载的文件类型
  183. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  184. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  185. readfile($file);
  186. }
  187. //PC下载会员注册码 ssh 2020.2.29
  188. public function actionApplyMemberCode()
  189. {
  190. $id = Yii::$app->request->get('id', 0);
  191. $extend = MerchantExtendService::getBySjId($this->sjId);
  192. if ($extend['miniAuth'] == 0) {
  193. util::fail('您的小程序还没有授权');
  194. }
  195. $shop = ShopService::getById($id);
  196. ShopClass::valid($shop, $this->sjId);
  197. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  198. $file = dirUtil::getImgDir() . $applyMemberCode;
  199. if (file_exists($file) == false) {
  200. util::fail('没有找到注册会员码');
  201. }
  202. if (httpUtil::isMiniProgram()) {
  203. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  204. util::success(['imgUrl' => $imgUrl]);
  205. }
  206. $fileName = "注册会员码{$id}.jpg";
  207. $contentType = 'image/jpeg';
  208. header("Cache-control: private");
  209. header("Content-type: $contentType"); //设置要下载的文件类型
  210. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  211. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  212. readfile($file);
  213. }
  214. //删除门店 ssh 2020.3.1
  215. public function actionDelete()
  216. {
  217. util::fail('禁止操作');
  218. $id = Yii::$app->request->get('id', 0);
  219. $shop = ShopService::getById($id);
  220. ShopClass::valid($shop, $this->sjId);
  221. ShopClass::deleteShop($shop);
  222. util::complete();
  223. }
  224. //获取所有门店lqh 2021.1.31
  225. public function actionAll()
  226. {
  227. $res = ShopClass::getAllShop($this->sjId);
  228. util::success($res);
  229. }
  230. //切换门店 lqh 2021.1.31
  231. public function actionToggleShop()
  232. {
  233. $newShopId = Yii::$app->request->post('shopId', 0);
  234. $newShop = ShopClass::getById($newShopId, true);
  235. if (empty($newShop)) {
  236. util::fail('没有找到门店');
  237. }
  238. $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  239. util::success($res);
  240. }
  241. //提现信息更新 ssh 2021.3.23
  242. public function actionCashUpdate()
  243. {
  244. $get = Yii::$app->request->get();
  245. $cashAccount = $get['cashAccount'] ?? '';
  246. $cashName = $get['cashName'] ?? '';
  247. $cashBank = $get['cashBank'] ?? '';
  248. if (empty($cashName)) {
  249. util::fail('请填写姓名');
  250. }
  251. if (empty($cashAccount)) {
  252. util::fail('请填写银行卡号');
  253. }
  254. if (empty($cashBank)) {
  255. util::fail('请输入开户行');
  256. }
  257. $shopAdmin = $this->shopAdmin;
  258. $mainId = $shopAdmin->mainId ?? 0;
  259. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  260. util::fail('超管才能操作');
  261. }
  262. MainClass::updateById($mainId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  263. util::complete();
  264. }
  265. //获取门店详情 ssh 2021.4.23
  266. public function actionDetail()
  267. {
  268. $shopId = Yii::$app->request->get('shopId');
  269. if (empty($shopId)) {
  270. $shopId = $this->shopId;
  271. }
  272. $shop = ShopClass::getShopInfo($shopId);
  273. util::success(['info' => $shop]);
  274. }
  275. //获取平台所有的供应商门店 ssh 20210908
  276. public function actionGetPtGhsShop()
  277. {
  278. $shop = ShopClass::getAllByCondition(['ptStyle' => 2], 'id asc', '*');
  279. util::success(['list' => $shop]);
  280. }
  281. //切换门店 ssh 20210908
  282. public function actionSwitchGhsShop()
  283. {
  284. $shopAdmin = $this->shopAdmin;
  285. $adminId = $shopAdmin->adminId ?? 0;
  286. if ($adminId != 2) {
  287. util::fail('没有权限');
  288. }
  289. $shopId = Yii::$app->request->get('shopId', 0);
  290. $admin = \biz\admin\classes\AdminClass::getById($adminId, true);
  291. if (empty($admin)) {
  292. util::fail('没有找到这个管理员');
  293. }
  294. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId], true);
  295. if (empty($shopAdmin)) {
  296. util::fail('不是本店员工');
  297. }
  298. $admin->currentShopId = $shopId;
  299. $admin->save();
  300. util::complete();
  301. }
  302. //散客门店详情 ssh 20211007
  303. public function actionSkCustom()
  304. {
  305. $skCustomId = $this->shop->skCustomId ?? 0;
  306. $custom = [];
  307. if (!empty($skCustomId)) {
  308. $custom = CustomClass::getById($skCustomId);
  309. $avatar = $custom['avatar'] ?? '';
  310. $custom['avatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  311. }
  312. util::success(['custom' => $custom]);
  313. }
  314. //散客门店设置
  315. public function actionSkCustomSet()
  316. {
  317. $id = Yii::$app->request->get('id', 0);
  318. $custom = CustomClass::getById($id, true);
  319. CustomClass::valid($custom, $this->shopId);
  320. $this->shop->skCustomId = $id;
  321. $this->shop->save();
  322. util::complete('修改成功');
  323. }
  324. //运费模式和运费成本设置 ssh 20211014
  325. public function actionUpdateCgModel()
  326. {
  327. $get = Yii::$app->request->get();
  328. $cgModel = $get['cgModel'] ?? 0;
  329. $cgPerCost = $get['cgPerCost'] ?? 0;
  330. if ($cgModel == 1) {
  331. if (is_numeric($cgPerCost) == false || $cgPerCost < 0) {
  332. util::fail('请输入运费成本');
  333. }
  334. $this->shop->cgPerCost = $cgPerCost;
  335. }
  336. $this->shop->cgModel = $cgModel;
  337. $this->shop->save();
  338. util::complete('修改成功');
  339. }
  340. //地区 ssh 20220606
  341. public function actionRegion()
  342. {
  343. $regionTree = RegionService::tree();
  344. util::success(['region' => $regionTree]);
  345. }
  346. }