ShopController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace business\controllers;
  3. use biz\merchant\services\ShopService;
  4. use common\components\dirUtil;
  5. use common\components\util;
  6. use Yii;
  7. class ShopController extends BaseController
  8. {
  9. //门店列表 shish 20202.2.29
  10. public function actionList()
  11. {
  12. $where = [];
  13. $where['merchantId'] = $this->merchantId;
  14. $where['delStatus'] = 0;
  15. $list = ShopService::getShopList($where);
  16. util::success($list);
  17. }
  18. //更新门店 shish 2020.2.29
  19. public function actionUpdate()
  20. {
  21. $data = Yii::$app->request->post();
  22. $data['merchantId'] = $this->merchantId;
  23. $id = isset($data['id']) ? $data['id'] : 0;
  24. unset($data['id']);
  25. $shop = ShopService::getById($id);
  26. ShopService::valid($shop, $this->merchantId);
  27. ShopService::updateShop($id, $data);
  28. util::ok();
  29. }
  30. public function actionAdd()
  31. {
  32. $data = Yii::$app->request->post();
  33. $data['merchantId'] = $this->merchantId;
  34. ShopService::addShop($data);
  35. util::ok();
  36. }
  37. //下载收款码 shish 2020.2.29
  38. public function actionDownloadGatheringCode()
  39. {
  40. $id = Yii::$app->request->get('id', 0);
  41. $shop = ShopService::getById($id);
  42. ShopService::valid($shop, $this->merchantId);
  43. $gatheringCode = isset($shop['gatheringCode']) ? $shop['gatheringCode'] : '';
  44. if (empty($gatheringCode)) {
  45. util::fail('没有收款码');
  46. }
  47. $file = dirUtil::getImgDir() . $gatheringCode;
  48. if (file_exists($file) == false) {
  49. util::fail('没有找到收款码');
  50. }
  51. $fileName = 'gathering.jpg';
  52. $contentType = 'image/jpeg';
  53. header("Cache-control: private");
  54. header("Content-type: $contentType"); //设置要下载的文件类型
  55. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  56. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  57. readfile($file);
  58. }
  59. //下载注册会员码 shish 2020.2.29
  60. public function actionDownloadApplyMemberCode()
  61. {
  62. $id = Yii::$app->request->get('id', 0);
  63. $shop = ShopService::getById($id);
  64. ShopService::valid($shop, $this->merchantId);
  65. $applyMemberCode = isset($shop['applyMemberCode']) ? $shop['applyMemberCode'] : '';
  66. if (empty($applyMemberCode)) {
  67. util::fail('没有注册会员码');
  68. }
  69. $file = dirUtil::getImgDir() . $applyMemberCode;
  70. if (file_exists($file) == false) {
  71. util::fail('没有找到注册会员码');
  72. }
  73. $fileName = 'member.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::ok();
  89. }
  90. }