ShopController.php 13 KB

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