ShopController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 bizHd\merchant\services\ShopService;
  7. use common\components\dict;
  8. use common\components\dirUtil;
  9. use common\components\util;
  10. use common\components\wxUtil;
  11. use Yii;
  12. class ShopController extends BaseController
  13. {
  14. public $guestAccess = ['all'];
  15. //获取当前门店信息 ssh 2021.3.27
  16. public function actionCurrentShop()
  17. {
  18. $shop = $this->shop->attributes;
  19. util::success($shop);
  20. }
  21. //门店列表 ssh 20202.2.29
  22. public function actionList()
  23. {
  24. $where = [];
  25. $where['sjId'] = $this->sjId;
  26. $where['delStatus'] = 0;
  27. $list = \bizGhs\merchant\classes\ShopClass::getShopList($where);
  28. util::success($list);
  29. }
  30. //更新门店 ssh 2020.2.29
  31. public function actionUpdate()
  32. {
  33. $data = Yii::$app->request->post();
  34. $data['sjId'] = $this->sjId;
  35. $id = isset($data['id']) ? $data['id'] : 0;
  36. unset($data['id']);
  37. $shop = ShopService::getById($id);
  38. ShopService::valid($shop, $this->sjId);
  39. $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
  40. ShopClass::updateShop($shop, $data);
  41. util::complete();
  42. }
  43. public function actionAdd()
  44. {
  45. $data = Yii::$app->request->post();
  46. $data['sjId'] = $this->sjId;
  47. $data['shopId'] = $this->shopId;
  48. $data['adminId'] = $this->adminId;
  49. $data['img'] = is_array($data['img']) ? json_encode($data['img']) : $data['img'];
  50. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  51. util::fail('请填写门店名称');
  52. }
  53. $sj = $this->sj->attributes;
  54. $sjName = $sj['name'] ?? '';
  55. $data['merchantName'] = $sjName;
  56. $ptStyle = $sj['style'] ?? dict::getDict('ptStyle', 'hd');
  57. $data['ptStyle'] = $ptStyle;
  58. $connection = Yii::$app->db;
  59. $transaction = $connection->beginTransaction();
  60. try {
  61. ShopClass::addShop($data);
  62. $transaction->commit();
  63. util::complete();
  64. } catch (\Exception $exception) {
  65. $transaction->rollBack();
  66. util::fail();
  67. }
  68. }
  69. //切换门店 linqh 2021.1.31
  70. public function actionToggleShop()
  71. {
  72. $shopId = Yii::$app->request->post('shopId', 0);
  73. $res = AdminClass::toggleShop($this->admin->attributes, $shopId, $this->sjId, $this->shopAdmin->attributes);
  74. util::success($res);
  75. }
  76. //下载微信和支付宝收款码 ssh 2020.2.29
  77. public function actionGatheringCode()
  78. {
  79. $id = Yii::$app->request->get('id', 0);
  80. $shop = ShopService::getById($id, true);
  81. if (empty($shop)) {
  82. util::fail('没有找到门店');
  83. }
  84. ShopService::valid($shop->attributes, $this->sjId);
  85. $gatheringCode = ShopService::generateGatheringCode($this->sjId, $id);
  86. $filename = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode . '?x-oss-process=image/resize,P_55') . ',g_nw,x_278,y_465/watermark,image_' . base64_encode('gathering/logo.jpg') . ',g_nw,x_510,y_685';
  87. $shopName = $shop->shopName ?? '';
  88. $file = fopen($filename, "rb");
  89. Header("Content-type: application/octet-stream ");
  90. Header("Accept-Ranges: bytes ");
  91. Header("Content-Disposition: attachment;filename={$shopName}收款码.jpg");
  92. $contents = "";
  93. while (!feof($file)) {
  94. $contents .= fread($file, 8192);
  95. }
  96. echo $contents;
  97. fclose($file);
  98. }
  99. //获取小程序的收款码 ssh
  100. public function actionGatheringMiniCode()
  101. {
  102. $id = Yii::$app->request->get('id', 0);
  103. $extend = MerchantExtendService::getBySjId($this->sjId);
  104. if ($extend['miniAuth'] == 0) {
  105. util::fail('您的小程序还没有授权');
  106. }
  107. $shop = ShopService::getById($id);
  108. ShopService::valid($shop, $this->sjId);
  109. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  110. $file = dirUtil::getImgDir() . $applyMemberCode;
  111. if (file_exists($file) == false) {
  112. util::fail('没有找到注册会员码');
  113. }
  114. $fileName = "门店({$id})小程序收款码.jpg";
  115. $contentType = 'image/jpeg';
  116. header("Cache-control: private");
  117. header("Content-type: $contentType"); //设置要下载的文件类型
  118. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  119. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  120. readfile($file);
  121. }
  122. //下载会员注册码 ssh 2020.2.29
  123. public function actionApplyMemberCode()
  124. {
  125. $id = Yii::$app->request->get('id', 0);
  126. $extend = MerchantExtendService::getBySjId($this->sjId);
  127. if ($extend['miniAuth'] == 0) {
  128. util::fail('您的小程序还没有授权');
  129. }
  130. $shop = ShopService::getById($id);
  131. ShopService::valid($shop, $this->sjId);
  132. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  133. $file = dirUtil::getImgDir() . $applyMemberCode;
  134. if (file_exists($file) == false) {
  135. util::fail('没有找到注册会员码');
  136. }
  137. $fileName = "注册会员码{$id}.jpg";
  138. $contentType = 'image/jpeg';
  139. header("Cache-control: private");
  140. header("Content-type: $contentType"); //设置要下载的文件类型
  141. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  142. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  143. readfile($file);
  144. }
  145. //删除门店 ssh 2020.3.1
  146. public function actionDelete()
  147. {
  148. util::fail('禁止操作');
  149. $id = Yii::$app->request->get('id', 0);
  150. util::fail('功能开发中');
  151. $shop = ShopService::getById($id);
  152. ShopService::valid($shop, $this->sjId);
  153. ShopService::deleteShop($shop);
  154. util::complete();
  155. }
  156. //获取门店详情 ssh 2021.4.23
  157. public function actionDetail()
  158. {
  159. $shopId = Yii::$app->request->get('shopId');
  160. if (empty($shopId)) {
  161. $shopId = $this->shopId;
  162. }
  163. $shop = ShopClass::getShopInfo($shopId);
  164. util::success(['info' => $shop]);
  165. }
  166. //提现信息更新 ssh 2021.3.23
  167. public function actionCashUpdate()
  168. {
  169. $get = Yii::$app->request->get();
  170. $cashAccount = $get['cashAccount'] ?? '';
  171. $cashName = $get['cashName'] ?? '';
  172. if (empty($cashName)) {
  173. util::fail('请填写姓名');
  174. }
  175. if (empty($cashAccount)) {
  176. util::fail('请填写帐号');
  177. }
  178. $shopAdmin = $this->shopAdmin->attributes;
  179. $shopId = $shopAdmin['shopId'];
  180. if ($shopAdmin['super'] != 1) {
  181. util::fail('超管才能操作');
  182. }
  183. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  184. util::complete();
  185. }
  186. //获取所有门店linqh 2021.1.31
  187. public function actionAll()
  188. {
  189. $res = [];
  190. $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
  191. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  192. $res = ShopClass::getAllShop($this->sjId);
  193. }
  194. util::success($res);
  195. }
  196. }