ShopController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use bizHd\merchant\services\ShopService;
  6. use common\components\dirUtil;
  7. use common\components\util;
  8. use common\components\wxUtil;
  9. use Yii;
  10. class ShopController extends BaseController
  11. {
  12. public $guestAccess = ['all'];
  13. //门店列表 ssh 20202.2.29
  14. public function actionList()
  15. {
  16. $where = [];
  17. $where['merchantId'] = $this->sjId;
  18. $where['delStatus'] = 0;
  19. $list = ShopService::getShopList($where);
  20. util::success($list);
  21. }
  22. //更新门店 ssh 2020.2.29
  23. public function actionUpdate()
  24. {
  25. $data = Yii::$app->request->post();
  26. $data['merchantId'] = $this->sjId;
  27. $id = isset($data['id']) ? $data['id'] : 0;
  28. unset($data['id']);
  29. $shop = ShopService::getById($id);
  30. ShopService::valid($shop, $this->sjId);
  31. ShopService::updateShop($id, $data);
  32. util::complete();
  33. }
  34. public function actionAdd()
  35. {
  36. $data = Yii::$app->request->post();
  37. $data['merchantId'] = $this->sjId;
  38. ShopService::addShop($data);
  39. util::complete();
  40. }
  41. //下载微信和支付宝收款码 ssh 2020.2.29
  42. public function actionGatheringCode()
  43. {
  44. $id = Yii::$app->request->get('id', 0);
  45. $shop = ShopService::getById($id);
  46. ShopService::valid($shop, $this->sjId);
  47. $gatheringCode = ShopService::generateGatheringCode($this->sjId, $id);
  48. $file = dirUtil::getImgDir() . $gatheringCode;
  49. if (file_exists($file) == false) {
  50. util::fail('没有找到收款码');
  51. }
  52. $fileName = "门店({$id})收款码.jpg";
  53. $contentType = 'image/jpeg';
  54. header("Cache-control: private");
  55. header("Content-type: $contentType"); //设置要下载的文件类型
  56. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  57. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  58. readfile($file);
  59. }
  60. //获取小程序的收款码 ssh
  61. public function actionGatheringMiniCode()
  62. {
  63. $id = Yii::$app->request->get('id', 0);
  64. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  65. if ($extend['miniAuth'] == 0) {
  66. util::fail('您的小程序还没有授权');
  67. }
  68. $shop = ShopService::getById($id);
  69. ShopService::valid($shop, $this->sjId);
  70. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  71. $file = dirUtil::getImgDir() . $applyMemberCode;
  72. if (file_exists($file) == false) {
  73. util::fail('没有找到注册会员码');
  74. }
  75. $fileName = "门店({$id})小程序收款码.jpg";
  76. $contentType = 'image/jpeg';
  77. header("Cache-control: private");
  78. header("Content-type: $contentType"); //设置要下载的文件类型
  79. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  80. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  81. readfile($file);
  82. }
  83. //下载会员注册码 ssh 2020.2.29
  84. public function actionApplyMemberCode()
  85. {
  86. $id = Yii::$app->request->get('id', 0);
  87. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  88. if ($extend['miniAuth'] == 0) {
  89. util::fail('您的小程序还没有授权');
  90. }
  91. $shop = ShopService::getById($id);
  92. ShopService::valid($shop, $this->sjId);
  93. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  94. $file = dirUtil::getImgDir() . $applyMemberCode;
  95. if (file_exists($file) == false) {
  96. util::fail('没有找到注册会员码');
  97. }
  98. $fileName = "注册会员码{$id}.jpg";
  99. $contentType = 'image/jpeg';
  100. header("Cache-control: private");
  101. header("Content-type: $contentType"); //设置要下载的文件类型
  102. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  103. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  104. readfile($file);
  105. }
  106. //删除门店 ssh 2020.3.1
  107. public function actionDelete()
  108. {
  109. $id = Yii::$app->request->get('id', 0);
  110. util::fail('功能开发中');
  111. $shop = ShopService::getById($id);
  112. ShopService::valid($shop, $this->sjId);
  113. ShopService::deleteShop($shop);
  114. util::complete();
  115. }
  116. //获取商家的默认门店 ssh 2019.12.6
  117. public function actionDetail()
  118. {
  119. $introUserId = Yii::$app->request->get('introUserId');
  120. //$merchant = $this->sj;
  121. //$shop = ShopService::getDefaultShop($merchant);
  122. //$ad = AdService::getValidAdList($this->sjId);
  123. //新人专享礼物
  124. $newUserGift = [
  125. [
  126. 'adImgUrl' => "https://img.huahb.com/uploads/12358/202006/03/20210120220152.jpg",
  127. 'adName' => '图片',
  128. ],
  129. ];
  130. if (!empty($introUserId)) {
  131. //$userInfo = UserService::getUserInfo($this->adminId);
  132. //$newUserGift = InviteService::hasNewGift($userInfo);
  133. }
  134. $ad = [];
  135. $shop = [
  136. 'address' => '福建省厦门市思明区后埭溪路128-5号',
  137. 'telephone' => '15280215347',
  138. 'openTime' => '09:00--18:00',
  139. 'shopName' => '国兰花尚',
  140. 'name' => '国兰花尚2',
  141. 'introduction' => '门店介绍',
  142. ];
  143. util::success(['ad' => $ad, 'shop' => $shop, 'newUserGift' => $newUserGift]);
  144. }
  145. //提现信息更新 ssh 2021.3.23
  146. public function actionCashUpdate()
  147. {
  148. $get = Yii::$app->request->get();
  149. $cashAccount = $get['cashAccount'] ?? '';
  150. $cashName = $get['cashName'] ?? '';
  151. if (empty($cashName)) {
  152. util::fail('请填写姓名');
  153. }
  154. if (empty($cashAccount)) {
  155. util::fail('请填写帐号');
  156. }
  157. $shopAdmin = $this->shopAdmin;
  158. $shopId = $shopAdmin['shopId'];
  159. if ($shopAdmin['super'] != 1) {
  160. util::fail('您没有权限修改');
  161. }
  162. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  163. util::complete();
  164. }
  165. //获取所有门店linqh 2021.1.31
  166. public function actionAll()
  167. {
  168. $res = [];
  169. $shopAdmin = $this->shopAdmin;
  170. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  171. $res = ShopClass::getAllShop($this->sjId);
  172. }
  173. util::success($res);
  174. }
  175. }