ShopController.php 12 KB

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