ShopController.php 10 KB

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