ShopController.php 6.6 KB

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