ShopController.php 10 KB

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