ShopController.php 12 KB

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