ShopController.php 5.9 KB

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