ShopController.php 11 KB

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