ShopController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\sj\services\MerchantExtendService;
  4. use bizGhs\admin\classes\AdminClass;
  5. use bizGhs\merchant\classes\ShopClass;
  6. use bizGhs\merchant\services\ShopService;
  7. use bizGhs\product\classes\ProductClass;
  8. use common\components\dirUtil;
  9. use common\components\httpUtil;
  10. use common\components\imgUtil;
  11. use common\components\util;
  12. use common\components\wxUtil;
  13. use jzweb\open\weixin\lib\user;
  14. use Yii;
  15. use yii\web\UrlManager;
  16. class ShopController extends BaseController
  17. {
  18. public $guestAccess = ['all'];
  19. //获取当前门店信息 ssh 2021.3.27
  20. public function actionCurrentShop()
  21. {
  22. $shop = $this->shop;
  23. util::success($shop);
  24. }
  25. //门店列表 ssh 2021.1.14
  26. public function actionList()
  27. {
  28. $where = [];
  29. $where['merchantId'] = $this->sjId;
  30. $where['delStatus'] = 0;
  31. $list = ShopClass::getShopList($where);
  32. util::success($list);
  33. }
  34. //更新门店 ssh 2020.2.29
  35. public function actionUpdate()
  36. {
  37. $data = Yii::$app->request->post();
  38. $data['merchantId'] = $this->sjId;
  39. $id = $data['id'] ?? 0;
  40. $shop = ShopService::getById($id);
  41. if (empty($shop)) {
  42. util::fail('没有找到门店');
  43. }
  44. ShopClass::valid($shop, $this->sjId);
  45. ShopClass::updateShop($id, $data);
  46. util::complete();
  47. }
  48. //添加门店 ssh 2021.1.14
  49. public function actionAdd()
  50. {
  51. $data = Yii::$app->request->post();
  52. $data['merchantId'] = $this->sjId;
  53. $connection = Yii::$app->db;
  54. $transaction = $connection->beginTransaction();
  55. try {
  56. $shop = ShopClass::addShop($data);
  57. $shopId = $shop['id'];
  58. //门店product 同步数据 linqh 2021.4.18
  59. $product = ProductClass::getAllProduct($this->sjId, $this->shopId, "name,cover,classId,itemId,rank,price,priceLabel,cost,addPrice,stockWarning,weight,alias,py,ratio,bigUnit,smallUnit,bigUnitId,smallUnitId,inTurn");
  60. $productData = [];
  61. foreach ($product as $v) {
  62. $tmp = $v;
  63. $tmp['merchantId'] = $this->sjId;
  64. $tmp['shopId'] = $shopId;
  65. $tmp['adminId'] = $this->adminId;
  66. $productData[] = $tmp;
  67. }
  68. ProductClass::batchAdd($productData);
  69. $transaction->commit();
  70. util::complete();
  71. } catch (\Exception $exception) {
  72. $transaction->rollBack();
  73. util::fail();
  74. }
  75. }
  76. //PC下载微信和支付宝收款码 ssh 2020.2.29
  77. public function actionGatheringCode()
  78. {
  79. $id = Yii::$app->request->get('id', 0);
  80. $shop = ShopService::getById($id);
  81. ShopClass::valid($shop, $this->sjId);
  82. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  83. $file = dirUtil::getImgDir() . $gatheringCode;
  84. if (file_exists($file) == false) {
  85. util::fail('没有找到收款码');
  86. }
  87. if (httpUtil::isMiniProgram()) {
  88. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  89. util::success(['imgUrl' => $imgUrl]);
  90. }
  91. $fileName = "门店({$id})收款码.jpg";
  92. $contentType = 'image/jpeg';
  93. header("Cache-control: private");
  94. header("Content-type: $contentType"); //设置要下载的文件类型
  95. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  96. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  97. readfile($file);
  98. }
  99. //PC获取小程序的收款码 ssh
  100. public function actionGatheringMiniCode()
  101. {
  102. $id = Yii::$app->request->get('id', 0);
  103. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  104. if ($extend['miniAuth'] == 0) {
  105. util::fail('您的小程序还没有授权');
  106. }
  107. $shop = ShopService::getById($id);
  108. ShopClass::valid($shop, $this->sjId);
  109. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj, $id);
  110. $file = dirUtil::getImgDir() . $applyMemberCode;
  111. if (file_exists($file) == false) {
  112. util::fail('没有找到注册会员码');
  113. }
  114. if (httpUtil::isMiniProgram()) {
  115. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  116. util::success(['imgUrl' => $imgUrl]);
  117. }
  118. $fileName = "门店({$id})小程序收款码.jpg";
  119. $contentType = 'image/jpeg';
  120. header("Cache-control: private");
  121. header("Content-type: $contentType"); //设置要下载的文件类型
  122. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  123. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  124. readfile($file);
  125. }
  126. //PC下载会员注册码 ssh 2020.2.29
  127. public function actionApplyMemberCode()
  128. {
  129. $id = Yii::$app->request->get('id', 0);
  130. $extend = MerchantExtendService::getByMerchantId($this->sjId);
  131. if ($extend['miniAuth'] == 0) {
  132. util::fail('您的小程序还没有授权');
  133. }
  134. $shop = ShopService::getById($id);
  135. ShopClass::valid($shop, $this->sjId);
  136. $applyMemberCode = wxUtil::generateMemberCode($this->sj, $id);
  137. $file = dirUtil::getImgDir() . $applyMemberCode;
  138. if (file_exists($file) == false) {
  139. util::fail('没有找到注册会员码');
  140. }
  141. if (httpUtil::isMiniProgram()) {
  142. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  143. util::success(['imgUrl' => $imgUrl]);
  144. }
  145. $fileName = "注册会员码{$id}.jpg";
  146. $contentType = 'image/jpeg';
  147. header("Cache-control: private");
  148. header("Content-type: $contentType"); //设置要下载的文件类型
  149. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  150. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  151. readfile($file);
  152. }
  153. //删除门店 ssh 2020.3.1
  154. public function actionDelete()
  155. {
  156. $id = Yii::$app->request->get('id', 0);
  157. $shop = ShopService::getById($id);
  158. ShopClass::valid($shop, $this->sjId);
  159. ShopClass::deleteShop($shop);
  160. util::complete();
  161. }
  162. //获取所有门店linqh 2021.1.31
  163. public function actionAll()
  164. {
  165. $res = [];
  166. $shopAdmin = $this->shopAdmin;
  167. if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
  168. $res = ShopClass::getAllShop($this->sjId);
  169. }
  170. util::success($res);
  171. }
  172. //切换门店 linqh 2021.1.31
  173. public function actionToggleShop()
  174. {
  175. $shopId = Yii::$app->request->post('shopId', 0);
  176. $res = AdminClass::toggleShop($this->admin, $shopId, $this->sjId, $this->shopAdmin);
  177. util::success($res);
  178. }
  179. //提现信息更新 ssh 2021.3.23
  180. public function actionCashUpdate()
  181. {
  182. $get = Yii::$app->request->get();
  183. $cashAccount = $get['cashAccount'] ?? '';
  184. $cashName = $get['cashName'] ?? '';
  185. if (empty($cashName)) {
  186. util::fail('请填写姓名');
  187. }
  188. if (empty($cashAccount)) {
  189. util::fail('请填写帐号');
  190. }
  191. $shopAdmin = $this->shopAdmin;
  192. $shopId = $shopAdmin['shopId'];
  193. if ($shopAdmin['super'] != 1) {
  194. util::fail('您没有权限修改');
  195. }
  196. ShopClass::updateById($shopId, ['cashAccount' => $cashAccount, 'cashName' => $cashName]);
  197. util::complete();
  198. }
  199. //获取门店详情 ssh 2021.4.23
  200. public function actionDetail()
  201. {
  202. $shopId = Yii::$app->request->get('shopId');
  203. if (empty($shopId)) {
  204. $shopId = $this->shopId;
  205. }
  206. $shop = ShopClass::getShopInfo($shopId);
  207. util::success(['info' => $shop]);
  208. }
  209. }