ShopController.php 12 KB

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