ShopController.php 11 KB

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