ShopController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use bizGhs\admin\classes\AdminClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizHd\merchant\services\ShopService;
  8. use bizHd\purchase\classes\PurchaseClass;
  9. use bizHd\saas\services\RegionService;
  10. use common\components\dict;
  11. use common\components\dirUtil;
  12. use common\components\noticeUtil;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use common\components\wxUtil;
  16. use Yii;
  17. class ShopController extends BaseController
  18. {
  19. public $guestAccess = ['all', 'gathering-img-url', 'check-shop'];
  20. //是否开启完整功能 ssh 20230226
  21. public function actionChangeOnlyCg()
  22. {
  23. $shop = $this->shop;
  24. $get = Yii::$app->request->get();
  25. $onlyCg = $get['onlyCg'] ?? 1;
  26. $shop->onlyCg = $onlyCg;
  27. $shop->save();
  28. util::complete('操作成功');
  29. }
  30. public function actionCheckShop()
  31. {
  32. $get = Yii::$app->request->get();
  33. $mobile = $get['mobile'] ?? '';
  34. $shop = ShopClass::getByCondition(['mobile' => $mobile], true);
  35. if (!empty($shop)) {
  36. util::success(['has' => 1]);
  37. }
  38. util::success(['has' => 0]);
  39. }
  40. //获取当前门店信息 ssh 2021.3.27
  41. public function actionCurrentShop()
  42. {
  43. util::success($this->shop);
  44. }
  45. //门店列表 ssh 20202.2.29
  46. public function actionList()
  47. {
  48. $where = [];
  49. $where['sjId'] = $this->sjId;
  50. $where['delStatus'] = 0;
  51. $list = \bizHd\shop\classes\ShopClass::getShopList($where);
  52. util::success($list);
  53. }
  54. //更新门店 ssh 2020.2.29
  55. public function actionUpdate()
  56. {
  57. $data = Yii::$app->request->post();
  58. $data['sjId'] = $this->sjId;
  59. $id = isset($data['id']) ? $data['id'] : 0;
  60. unset($data['id']);
  61. $shop = ShopService::getById($id);
  62. ShopService::valid($shop, $this->sjId);
  63. $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
  64. ShopClass::updateShop($shop, $data);
  65. util::complete();
  66. }
  67. public function actionAdd()
  68. {
  69. $data = Yii::$app->request->post();
  70. $data['sjId'] = $this->sjId;
  71. $data['shopId'] = $this->shopId;
  72. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  73. util::fail('请填写门店名称');
  74. }
  75. $sj = $this->sj;
  76. $sjName = $sj->name ?? '';
  77. $data['merchantName'] = $sjName;
  78. $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
  79. $data['ptStyle'] = $ptStyle;
  80. $connection = Yii::$app->db;
  81. $transaction = $connection->beginTransaction();
  82. try {
  83. $mobile = $data['mobile'] ?? 0;
  84. if (stringUtil::isMobile($mobile) == false) {
  85. util::fail('请填写正确手机号');
  86. }
  87. $adminInfo = ['name' => $mobile, 'mobile' => $mobile];
  88. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  89. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  90. $adminId = $admin['id'] ?? 0;
  91. $data['adminId'] = $adminId;
  92. \bizHd\shop\classes\ShopClass::addMainShop($data, $this->shop, $this->sj);
  93. $transaction->commit();
  94. util::complete();
  95. } catch (\Exception $exception) {
  96. $transaction->rollBack();
  97. util::fail();
  98. }
  99. }
  100. //切换门店 lqh 2021.1.31
  101. public function actionToggleShop()
  102. {
  103. //惠雅鲜花员工不能切换门店
  104. $shopAdmin = $this->shopAdmin;
  105. $adminId = $shopAdmin->adminId ?? 0;
  106. if (in_array($adminId, [2812, 3539, 3735, 3407])) {
  107. util::fail('暂无权限');
  108. }
  109. $newShopId = Yii::$app->request->post('shopId', 0);
  110. $newShop = ShopClass::getById($newShopId, true);
  111. if (empty($newShop)) {
  112. util::fail('没有找到门店');
  113. }
  114. $res = \bizHd\admin\classes\AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  115. util::success($res);
  116. }
  117. //下载微信和支付宝收款码 ssh 2020.2.29
  118. public function actionGatheringCode()
  119. {
  120. $id = Yii::$app->request->get('id', 0);
  121. $shop = ShopService::getById($id, true);
  122. if (empty($shop)) {
  123. util::fail('没有找到门店');
  124. }
  125. ShopClass::valid($shop->attributes, $this->sjId);
  126. $imgUrl = ShopClass::generateGatheringCode($this->sjId, $id);
  127. $shopName = $shop->shopName ?? '';
  128. $file = fopen($imgUrl, "rb");
  129. Header("Content-type: application/octet-stream ");
  130. Header("Accept-Ranges: bytes ");
  131. Header("Content-Disposition: attachment;filename={$shopName}收款码.jpg");
  132. $contents = "";
  133. while (!feof($file)) {
  134. $contents .= fread($file, 8192);
  135. }
  136. echo $contents;
  137. fclose($file);
  138. }
  139. //获取二维码
  140. public function actionGetGatheringCodeUrl()
  141. {
  142. $id = Yii::$app->request->get('id', 0);
  143. $shop = ShopService::getById($id, true);
  144. if (empty($shop)) {
  145. util::fail('没有找到门店');
  146. }
  147. ShopClass::valid($shop->attributes, $this->sjId);
  148. $imgUrl = Yii::$app->params['hdHost'] . '/auth/gathering-img-url?id=' . $id;
  149. util::success(['url' => $imgUrl]);
  150. }
  151. public function actionGatheringImgUrl()
  152. {
  153. $id = Yii::$app->request->get('id', 0);
  154. $shop = ShopService::getById($id, true);
  155. if (empty($shop)) {
  156. util::fail('没有找到门店');
  157. }
  158. $sjId = $shop->sjId;
  159. $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
  160. $fileResource = file_get_contents($imgUrl);
  161. header('Content-type: image/jpeg');
  162. echo $fileResource;
  163. }
  164. //获取小程序的收款码 ssh
  165. public function actionGatheringMiniCode()
  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. ShopService::valid($shop, $this->sjId);
  174. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  175. $file = dirUtil::getImgDir() . $applyMemberCode;
  176. if (file_exists($file) == false) {
  177. util::fail('没有找到注册会员码');
  178. }
  179. $fileName = "门店({$id})小程序收款码.jpg";
  180. $contentType = 'image/jpeg';
  181. header("Cache-control: private");
  182. header("Content-type: $contentType"); //设置要下载的文件类型
  183. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  184. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  185. readfile($file);
  186. }
  187. //下载会员注册码 ssh 2020.2.29
  188. public function actionApplyMemberCode()
  189. {
  190. $id = Yii::$app->request->get('id', 0);
  191. $extend = MerchantExtendService::getBySjId($this->sjId);
  192. if ($extend['miniAuth'] == 0) {
  193. util::fail('您的小程序还没有授权');
  194. }
  195. $shop = ShopService::getById($id);
  196. ShopService::valid($shop, $this->sjId);
  197. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  198. $file = dirUtil::getImgDir() . $applyMemberCode;
  199. if (file_exists($file) == false) {
  200. util::fail('没有找到注册会员码');
  201. }
  202. $fileName = "注册会员码{$id}.jpg";
  203. $contentType = 'image/jpeg';
  204. header("Cache-control: private");
  205. header("Content-type: $contentType"); //设置要下载的文件类型
  206. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  207. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  208. readfile($file);
  209. }
  210. //删除门店 ssh 2020.3.1
  211. public function actionDelete()
  212. {
  213. util::fail('禁止操作');
  214. $id = Yii::$app->request->get('id', 0);
  215. util::fail('功能开发中');
  216. $shop = ShopService::getById($id);
  217. ShopService::valid($shop, $this->sjId);
  218. ShopService::deleteShop($shop);
  219. util::complete();
  220. }
  221. //获取门店详情 ssh 2021.4.23
  222. public function actionDetail()
  223. {
  224. $shopId = Yii::$app->request->get('shopId');
  225. if (empty($shopId)) {
  226. $shopId = $this->shopId;
  227. }
  228. $shop = ShopClass::getShopInfo($shopId);
  229. util::success(['info' => $shop]);
  230. }
  231. //提现信息更新 ssh 2021.3.23
  232. public function actionCashUpdate()
  233. {
  234. $get = Yii::$app->request->get();
  235. $cashAccount = $get['cashAccount'] ?? '';
  236. $cashName = $get['cashName'] ?? '';
  237. $cashBank = $get['cashBank'] ?? '';
  238. if (empty($cashName)) {
  239. util::fail('请填写姓名');
  240. }
  241. if (empty($cashAccount)) {
  242. util::fail('请填写银行卡号');
  243. }
  244. if (empty($cashBank)) {
  245. util::fail('请输入开户行');
  246. }
  247. $shopAdmin = $this->shopAdmin;
  248. $shopId = $shopAdmin->shopId ?? 0;
  249. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  250. util::fail('超管才能操作');
  251. }
  252. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  253. $shop = $this->shop;
  254. $sjName = $shop->merchantName ?? '';
  255. $shopName = $shop->shopName ?? '';
  256. noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347');
  257. util::complete();
  258. }
  259. //获取所有门店lqh 2021.1.31
  260. public function actionAll()
  261. {
  262. $res = [];
  263. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  264. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  265. $res = ShopClass::getAllShop($this->sjId);
  266. }
  267. util::success($res);
  268. }
  269. //获取采购时的支付方式 ssh 20211004
  270. public function actionGetCgPayWay()
  271. {
  272. $get = Yii::$app->request->get();
  273. $id = $get['id'] ?? 0;
  274. $cg = PurchaseClass::getById($id, true);
  275. PurchaseClass::valid($cg, $this->shopId);
  276. $customId = $cg->customId ?? 0;
  277. $custom = CustomClass::getById($customId);
  278. $hasDebtPay = $custom['debt'] ?? 0;
  279. //预订单不能欠款
  280. if ($cg->book == 1) {
  281. $hasDebtPay = 0;
  282. }
  283. $current = time();
  284. $cgDeadTime = strtotime($cg->deadline);
  285. //让客户在失效前$aheadTime秒要支付,这样回调通知时订单才不会过期状态
  286. $aheadTime = dict::getDict('order_online_pay_has_ahead_time');
  287. $count = $cgDeadTime - $current - $aheadTime;
  288. $data = [];
  289. $data['balance'] = $this->shop->balance ?? 0;
  290. $data['count'] = $count;
  291. $data['hasDebtPay'] = $hasDebtPay;
  292. util::success($data);
  293. }
  294. //地区 ssh 20220606
  295. public function actionRegion()
  296. {
  297. $regionTree = RegionService::tree();
  298. util::success(['region' => $regionTree]);
  299. }
  300. }