ShopController.php 13 KB

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