ShopController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 common\components\dict;
  10. use common\components\dirUtil;
  11. use common\components\util;
  12. use common\components\wxUtil;
  13. use Yii;
  14. class ShopController extends BaseController
  15. {
  16. public $guestAccess = ['all', 'gathering-img-url'];
  17. //获取当前门店信息 ssh 2021.3.27
  18. public function actionCurrentShop()
  19. {
  20. $shop = $this->shop->attributes;
  21. util::success($shop);
  22. }
  23. //门店列表 ssh 20202.2.29
  24. public function actionList()
  25. {
  26. $where = [];
  27. $where['sjId'] = $this->sjId;
  28. $where['delStatus'] = 0;
  29. $list = \bizGhs\merchant\classes\ShopClass::getShopList($where);
  30. util::success($list);
  31. }
  32. //更新门店 ssh 2020.2.29
  33. public function actionUpdate()
  34. {
  35. $data = Yii::$app->request->post();
  36. $data['sjId'] = $this->sjId;
  37. $id = isset($data['id']) ? $data['id'] : 0;
  38. unset($data['id']);
  39. $shop = ShopService::getById($id);
  40. ShopService::valid($shop, $this->sjId);
  41. $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
  42. ShopClass::updateShop($shop, $data);
  43. util::complete();
  44. }
  45. public function actionAdd()
  46. {
  47. $data = Yii::$app->request->post();
  48. $data['sjId'] = $this->sjId;
  49. $data['shopId'] = $this->shopId;
  50. $data['adminId'] = $this->adminId;
  51. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  52. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  53. util::fail('请填写门店名称');
  54. }
  55. $sj = $this->sj->attributes;
  56. $sjName = $sj['name'] ?? '';
  57. $data['merchantName'] = $sjName;
  58. $ptStyle = $sj['style'] ?? dict::getDict('ptStyle', 'hd');
  59. $data['ptStyle'] = $ptStyle;
  60. $connection = Yii::$app->db;
  61. $transaction = $connection->beginTransaction();
  62. try {
  63. ShopClass::addShop($data);
  64. $transaction->commit();
  65. util::complete();
  66. } catch (\Exception $exception) {
  67. $transaction->rollBack();
  68. util::fail();
  69. }
  70. }
  71. //切换门店 linqh 2021.1.31
  72. public function actionToggleShop()
  73. {
  74. $shopId = Yii::$app->request->post('shopId', 0);
  75. $res = AdminClass::toggleShop($this->admin->attributes, $shopId, $this->sjId, $this->shopAdmin->attributes);
  76. util::success($res);
  77. }
  78. //下载微信和支付宝收款码 ssh 2020.2.29
  79. public function actionGatheringCode()
  80. {
  81. $id = Yii::$app->request->get('id', 0);
  82. $shop = ShopService::getById($id, true);
  83. if (empty($shop)) {
  84. util::fail('没有找到门店');
  85. }
  86. ShopClass::valid($shop->attributes, $this->sjId);
  87. $imgUrl = ShopClass::generateGatheringCode($this->sjId, $id);
  88. $shopName = $shop->shopName ?? '';
  89. $file = fopen($imgUrl, "rb");
  90. Header("Content-type: application/octet-stream ");
  91. Header("Accept-Ranges: bytes ");
  92. Header("Content-Disposition: attachment;filename={$shopName}收款码.jpg");
  93. $contents = "";
  94. while (!feof($file)) {
  95. $contents .= fread($file, 8192);
  96. }
  97. echo $contents;
  98. fclose($file);
  99. }
  100. //获取二维码
  101. public function actionGetGatheringCodeUrl()
  102. {
  103. $id = Yii::$app->request->get('id', 0);
  104. $shop = ShopService::getById($id, true);
  105. if (empty($shop)) {
  106. util::fail('没有找到门店');
  107. }
  108. ShopClass::valid($shop->attributes, $this->sjId);
  109. $imgUrl = Yii::$app->params['hdHost'] . '/auth/gathering-img-url?id=' . $id;
  110. util::success(['url' => $imgUrl]);
  111. }
  112. public function actionGatheringImgUrl()
  113. {
  114. $id = Yii::$app->request->get('id', 0);
  115. $shop = ShopService::getById($id, true);
  116. if (empty($shop)) {
  117. util::fail('没有找到门店');
  118. }
  119. $sjId = $shop->sjId;
  120. $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
  121. $fileResource = file_get_contents($imgUrl);
  122. header('Content-type: image/jpeg');
  123. echo $fileResource;
  124. }
  125. //获取小程序的收款码 ssh
  126. public function actionGatheringMiniCode()
  127. {
  128. $id = Yii::$app->request->get('id', 0);
  129. $extend = MerchantExtendService::getBySjId($this->sjId);
  130. if ($extend['miniAuth'] == 0) {
  131. util::fail('您的小程序还没有授权');
  132. }
  133. $shop = ShopService::getById($id);
  134. ShopService::valid($shop, $this->sjId);
  135. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  136. $file = dirUtil::getImgDir() . $applyMemberCode;
  137. if (file_exists($file) == false) {
  138. util::fail('没有找到注册会员码');
  139. }
  140. $fileName = "门店({$id})小程序收款码.jpg";
  141. $contentType = 'image/jpeg';
  142. header("Cache-control: private");
  143. header("Content-type: $contentType"); //设置要下载的文件类型
  144. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  145. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  146. readfile($file);
  147. }
  148. //下载会员注册码 ssh 2020.2.29
  149. public function actionApplyMemberCode()
  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::generateMemberCode($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.3.1
  172. public function actionDelete()
  173. {
  174. util::fail('禁止操作');
  175. $id = Yii::$app->request->get('id', 0);
  176. util::fail('功能开发中');
  177. $shop = ShopService::getById($id);
  178. ShopService::valid($shop, $this->sjId);
  179. ShopService::deleteShop($shop);
  180. util::complete();
  181. }
  182. //获取门店详情 ssh 2021.4.23
  183. public function actionDetail()
  184. {
  185. $shopId = Yii::$app->request->get('shopId');
  186. if (empty($shopId)) {
  187. $shopId = $this->shopId;
  188. }
  189. $shop = ShopClass::getShopInfo($shopId);
  190. util::success(['info' => $shop]);
  191. }
  192. //提现信息更新 ssh 2021.3.23
  193. public function actionCashUpdate()
  194. {
  195. $get = Yii::$app->request->get();
  196. $cashAccount = $get['cashAccount'] ?? '';
  197. $cashName = $get['cashName'] ?? '';
  198. $cashBank = $get['cashBank'] ?? '';
  199. if (empty($cashName)) {
  200. util::fail('请填写姓名');
  201. }
  202. if (empty($cashAccount)) {
  203. util::fail('请填写银行卡号');
  204. }
  205. if (empty($cashBank)) {
  206. util::fail('请输入开户行');
  207. }
  208. $shopAdmin = $this->shopAdmin;
  209. $shopId = $shopAdmin->shopId ?? 0;
  210. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  211. util::fail('超管才能操作');
  212. }
  213. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  214. util::complete();
  215. }
  216. //获取所有门店linqh 2021.1.31
  217. public function actionAll()
  218. {
  219. $res = [];
  220. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  221. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  222. $res = ShopClass::getAllShop($this->sjId);
  223. }
  224. util::success($res);
  225. }
  226. //获取采购时的支付方式 shish 20211004
  227. public function actionGetCgPayWay()
  228. {
  229. $get = Yii::$app->request->get();
  230. $id = $get['id'] ?? 0;
  231. $cg = PurchaseClass::getById($id, true);
  232. PurchaseClass::valid($cg, $this->shopId);
  233. $customId = $cg->customId ?? 0;
  234. $custom = CustomClass::getById($customId);
  235. $hasDebtPay = $custom['debt'] ?? 0;
  236. $current = time();
  237. $cgDeadTime = strtotime($cg->deadline);
  238. //让客户在失效前$aheadTime秒要支付,这样回调通知时订单才不会过期状态
  239. $aheadTime = dict::getDict('order_online_pay_has_ahead_time');
  240. $count = ($cgDeadTime - $current - $aheadTime) > 0 ? ($cgDeadTime - $current) : 0;
  241. $data = [];
  242. $data['balance'] = $this->shop->balance ?? 0;
  243. $data['count'] = $count;
  244. $data['hasDebtPay'] = $hasDebtPay;
  245. util::success($data);
  246. }
  247. }