ShopController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace shop\controllers;
  3. use biz\merchant\services\MerchantExtendService;
  4. use biz\merchant\services\ShopService;
  5. use common\components\dirUtil;
  6. use common\components\util;
  7. use common\components\wxUtil;
  8. use Yii;
  9. class ShopController extends BaseController
  10. {
  11. //门店列表 shish 20202.2.29
  12. public function actionList()
  13. {
  14. $where = [];
  15. $where['merchantId'] = $this->merchantId;
  16. $where['delStatus'] = 0;
  17. $list = ShopService::getShopList($where);
  18. util::success($list);
  19. }
  20. //更新门店 shish 2020.2.29
  21. public function actionUpdate()
  22. {
  23. $data = Yii::$app->request->post();
  24. $data['merchantId'] = $this->merchantId;
  25. $id = isset($data['id']) ? $data['id'] : 0;
  26. unset($data['id']);
  27. $shop = ShopService::getById($id);
  28. ShopService::valid($shop, $this->merchantId);
  29. ShopService::updateShop($id, $data);
  30. util::complete();
  31. }
  32. public function actionAdd()
  33. {
  34. $data = Yii::$app->request->post();
  35. $data['merchantId'] = $this->merchantId;
  36. ShopService::addShop($data);
  37. util::complete();
  38. }
  39. //下载微信和支付宝收款码 shish 2020.2.29
  40. public function actionGatheringCode()
  41. {
  42. $id = Yii::$app->request->get('id', 0);
  43. $shop = ShopService::getById($id);
  44. ShopService::valid($shop, $this->merchantId);
  45. $gatheringCode = ShopService::generateGatheringCode($this->merchantId, $id);
  46. $file = dirUtil::getImgDir() . $gatheringCode;
  47. if (file_exists($file) == false) {
  48. util::fail('没有找到收款码');
  49. }
  50. $fileName = "门店({$id})收款码.jpg";
  51. $contentType = 'image/jpeg';
  52. header("Cache-control: private");
  53. header("Content-type: $contentType"); //设置要下载的文件类型
  54. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  55. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  56. readfile($file);
  57. }
  58. //获取小程序的收款码 shish
  59. public function actionGatheringMiniCode()
  60. {
  61. $id = Yii::$app->request->get('id', 0);
  62. $extend = MerchantExtendService::getByMerchantId($this->merchantId);
  63. if ($extend['miniAuth'] == 0) {
  64. util::fail('您的小程序还没有授权');
  65. }
  66. $shop = ShopService::getById($id);
  67. ShopService::valid($shop, $this->merchantId);
  68. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->merchant, $id);
  69. $file = dirUtil::getImgDir() . $applyMemberCode;
  70. if (file_exists($file) == false) {
  71. util::fail('没有找到注册会员码');
  72. }
  73. $fileName = "门店({$id})小程序收款码.jpg";
  74. $contentType = 'image/jpeg';
  75. header("Cache-control: private");
  76. header("Content-type: $contentType"); //设置要下载的文件类型
  77. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  78. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  79. readfile($file);
  80. }
  81. //下载会员注册码 shish 2020.2.29
  82. public function actionApplyMemberCode()
  83. {
  84. $id = Yii::$app->request->get('id', 0);
  85. $extend = MerchantExtendService::getByMerchantId($this->merchantId);
  86. if ($extend['miniAuth'] == 0) {
  87. util::fail('您的小程序还没有授权');
  88. }
  89. $shop = ShopService::getById($id);
  90. ShopService::valid($shop, $this->merchantId);
  91. $applyMemberCode = wxUtil::generateMemberCode($this->merchant, $id);
  92. $file = dirUtil::getImgDir() . $applyMemberCode;
  93. if (file_exists($file) == false) {
  94. util::fail('没有找到注册会员码');
  95. }
  96. $fileName = "注册会员码{$id}.jpg";
  97. $contentType = 'image/jpeg';
  98. header("Cache-control: private");
  99. header("Content-type: $contentType"); //设置要下载的文件类型
  100. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  101. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  102. readfile($file);
  103. }
  104. //删除门店 shish 2020.3.1
  105. public function actionDelete()
  106. {
  107. $id = Yii::$app->request->get('id', 0);
  108. util::fail('功能开发中');
  109. $shop = ShopService::getById($id);
  110. ShopService::valid($shop, $this->merchantId);
  111. ShopService::deleteShop($shop);
  112. util::complete();
  113. }
  114. }