ShopController.php 13 KB

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