ShopController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. $newShopId = Yii::$app->request->post('shopId', 0);
  94. $newShop = ShopClass::getById($newShopId, true);
  95. if (empty($newShop)) {
  96. util::fail('没有找到门店');
  97. }
  98. $res = \bizHd\admin\classes\AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  99. util::success($res);
  100. }
  101. //下载微信和支付宝收款码 ssh 2020.2.29
  102. public function actionGatheringCode()
  103. {
  104. $id = Yii::$app->request->get('id', 0);
  105. $shop = ShopService::getById($id, true);
  106. if (empty($shop)) {
  107. util::fail('没有找到门店');
  108. }
  109. ShopClass::valid($shop->attributes, $this->sjId);
  110. $imgUrl = ShopClass::generateGatheringCode($this->sjId, $id);
  111. $shopName = $shop->shopName ?? '';
  112. $file = fopen($imgUrl, "rb");
  113. Header("Content-type: application/octet-stream ");
  114. Header("Accept-Ranges: bytes ");
  115. Header("Content-Disposition: attachment;filename={$shopName}收款码.jpg");
  116. $contents = "";
  117. while (!feof($file)) {
  118. $contents .= fread($file, 8192);
  119. }
  120. echo $contents;
  121. fclose($file);
  122. }
  123. //获取二维码
  124. public function actionGetGatheringCodeUrl()
  125. {
  126. $id = Yii::$app->request->get('id', 0);
  127. $shop = ShopService::getById($id, true);
  128. if (empty($shop)) {
  129. util::fail('没有找到门店');
  130. }
  131. ShopClass::valid($shop->attributes, $this->sjId);
  132. $imgUrl = Yii::$app->params['hdHost'] . '/auth/gathering-img-url?id=' . $id;
  133. util::success(['url' => $imgUrl]);
  134. }
  135. public function actionGatheringImgUrl()
  136. {
  137. $id = Yii::$app->request->get('id', 0);
  138. $shop = ShopService::getById($id, true);
  139. if (empty($shop)) {
  140. util::fail('没有找到门店');
  141. }
  142. $sjId = $shop->sjId;
  143. $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
  144. $fileResource = file_get_contents($imgUrl);
  145. header('Content-type: image/jpeg');
  146. echo $fileResource;
  147. }
  148. //获取小程序的收款码 ssh
  149. public function actionGatheringMiniCode()
  150. {
  151. $id = Yii::$app->request->get('id', 0);
  152. $extend = MerchantExtendService::getBySjId($this->sjId);
  153. if ($extend['miniAuth'] == 0) {
  154. util::fail('您的小程序还没有授权');
  155. }
  156. $shop = ShopService::getById($id);
  157. ShopService::valid($shop, $this->sjId);
  158. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  159. $file = dirUtil::getImgDir() . $applyMemberCode;
  160. if (file_exists($file) == false) {
  161. util::fail('没有找到注册会员码');
  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.2.29
  172. public function actionApplyMemberCode()
  173. {
  174. $id = Yii::$app->request->get('id', 0);
  175. $extend = MerchantExtendService::getBySjId($this->sjId);
  176. if ($extend['miniAuth'] == 0) {
  177. util::fail('您的小程序还没有授权');
  178. }
  179. $shop = ShopService::getById($id);
  180. ShopService::valid($shop, $this->sjId);
  181. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  182. $file = dirUtil::getImgDir() . $applyMemberCode;
  183. if (file_exists($file) == false) {
  184. util::fail('没有找到注册会员码');
  185. }
  186. $fileName = "注册会员码{$id}.jpg";
  187. $contentType = 'image/jpeg';
  188. header("Cache-control: private");
  189. header("Content-type: $contentType"); //设置要下载的文件类型
  190. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  191. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  192. readfile($file);
  193. }
  194. //删除门店 ssh 2020.3.1
  195. public function actionDelete()
  196. {
  197. util::fail('禁止操作');
  198. $id = Yii::$app->request->get('id', 0);
  199. util::fail('功能开发中');
  200. $shop = ShopService::getById($id);
  201. ShopService::valid($shop, $this->sjId);
  202. ShopService::deleteShop($shop);
  203. util::complete();
  204. }
  205. //获取门店详情 ssh 2021.4.23
  206. public function actionDetail()
  207. {
  208. $shopId = Yii::$app->request->get('shopId');
  209. if (empty($shopId)) {
  210. $shopId = $this->shopId;
  211. }
  212. $shop = ShopClass::getShopInfo($shopId);
  213. util::success(['info' => $shop]);
  214. }
  215. //提现信息更新 ssh 2021.3.23
  216. public function actionCashUpdate()
  217. {
  218. $get = Yii::$app->request->get();
  219. $cashAccount = $get['cashAccount'] ?? '';
  220. $cashName = $get['cashName'] ?? '';
  221. $cashBank = $get['cashBank'] ?? '';
  222. if (empty($cashName)) {
  223. util::fail('请填写姓名');
  224. }
  225. if (empty($cashAccount)) {
  226. util::fail('请填写银行卡号');
  227. }
  228. if (empty($cashBank)) {
  229. util::fail('请输入开户行');
  230. }
  231. $shopAdmin = $this->shopAdmin;
  232. $shopId = $shopAdmin->shopId ?? 0;
  233. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  234. util::fail('超管才能操作');
  235. }
  236. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  237. $shop = $this->shop;
  238. $sjName = $shop->merchantName ?? '';
  239. $shopName = $shop->shopName ?? '';
  240. noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347');
  241. util::complete();
  242. }
  243. //获取所有门店lqh 2021.1.31
  244. public function actionAll()
  245. {
  246. $res = [];
  247. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  248. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  249. $res = ShopClass::getAllShop($this->sjId);
  250. }
  251. util::success($res);
  252. }
  253. //获取采购时的支付方式 ssh 20211004
  254. public function actionGetCgPayWay()
  255. {
  256. $get = Yii::$app->request->get();
  257. $id = $get['id'] ?? 0;
  258. $cg = PurchaseClass::getById($id, true);
  259. PurchaseClass::valid($cg, $this->shopId);
  260. $customId = $cg->customId ?? 0;
  261. $custom = CustomClass::getById($customId);
  262. $hasDebtPay = $custom['debt'] ?? 0;
  263. //预订单不能欠款
  264. if ($cg->book == 1) {
  265. $hasDebtPay = 0;
  266. }
  267. $current = time();
  268. $cgDeadTime = strtotime($cg->deadline);
  269. //让客户在失效前$aheadTime秒要支付,这样回调通知时订单才不会过期状态
  270. $aheadTime = dict::getDict('order_online_pay_has_ahead_time');
  271. $count = $cgDeadTime - $current - $aheadTime;
  272. $data = [];
  273. $data['balance'] = $this->shop->balance ?? 0;
  274. $data['count'] = $count;
  275. $data['hasDebtPay'] = $hasDebtPay;
  276. util::success($data);
  277. }
  278. //地区 ssh 20220606
  279. public function actionRegion()
  280. {
  281. $regionTree = RegionService::tree();
  282. util::success(['region' => $regionTree]);
  283. }
  284. }