ShopController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 actionDownloadGatheringCode()
  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 2020.2.29
  59. public function actionDownloadApplyMemberCode()
  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::generateMemberCode($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.3.1
  82. public function actionDelete()
  83. {
  84. $id = Yii::$app->request->get('id', 0);
  85. $shop = ShopService::getById($id);
  86. ShopService::valid($shop, $this->merchantId);
  87. ShopService::deleteShop($shop);
  88. util::complete();
  89. }
  90. }