Store.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\store\system;
  12. use app\services\other\QrcodeServices;
  13. use app\services\store\SystemStoreStaffServices;
  14. use app\validate\store\system\StoreValidate;
  15. use crmeb\services\DeliverySevices;
  16. use crmeb\utils\Canvas;
  17. use think\facade\App;
  18. use app\controller\store\AuthController;
  19. use app\services\store\SystemStoreServices;
  20. /**
  21. * 门店
  22. * Class Store
  23. * @package app\controller\store\system
  24. */
  25. class Store extends AuthController
  26. {
  27. public function __construct(App $app, SystemStoreServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 获取门店信息
  34. * @return mixed
  35. */
  36. public function info()
  37. {
  38. return app('json')->success($this->services->getStoreInfo($this->storeId));
  39. }
  40. /**
  41. * 修改当前登录门店
  42. * @return mixed
  43. */
  44. public function update(SystemStoreStaffServices $services)
  45. {
  46. $data = $this->request->postMore([
  47. ['image', ''],
  48. ['name', ''],
  49. ['introduction', ''],
  50. ['phone', ''],
  51. ['address', ''],
  52. ['province', ''],
  53. ['city', ''],
  54. ['area', ''],
  55. ['street', ''],
  56. ['valid_range', 0],
  57. ['detailed_address', ''],
  58. ['is_show', ''],
  59. ['day_time', []],
  60. ['latitude', ''],
  61. ['longitude', ''],
  62. ['is_store', 0],
  63. ['default_delivery', 1],
  64. ['customer_type', 1],
  65. ['home_style', 1],
  66. ['city_delivery_status', 1],
  67. ['city_delivery_type', 1],
  68. ['delivery_goods_type', 1],
  69. ['business', 0]
  70. ]);
  71. validate(StoreValidate::class)->check($data);
  72. [$data['day_start'], $data['day_end']] = $data['day_time'];
  73. $data['day_time'] = $data['day_time'] ? implode(' - ', $data['day_time']) : '';
  74. $data['valid_range'] = bcmul($data['valid_range'], '1000', 0);
  75. $phone = $this->services->value(['id' => $this->storeId], 'phone');
  76. if ($this->services->update($this->storeId, $data)) {
  77. if ($phone) {
  78. $services->update(['phone' => $phone], ['phone' => $data['phone']]);
  79. }
  80. $storeInfo = $this->services->get((int)$this->storeId);
  81. $this->services->cacheUpdate($storeInfo->toArray());
  82. return app('json')->success('修改成功');
  83. } else {
  84. return app('json')->fail('修改失败');
  85. }
  86. }
  87. /**
  88. * 获取门店财务信息
  89. * @return mixed
  90. */
  91. public function getFinanceInfo()
  92. {
  93. $storeInfo = $this->services->get((int)$this->storeId);
  94. if (!$storeInfo) {
  95. return app('json')->fail('门店不存在');
  96. }
  97. return app('json')->success($storeInfo->toArray());
  98. }
  99. /**
  100. * 设置门店财务信息
  101. * @return mixed
  102. */
  103. public function setFinanceInfo()
  104. {
  105. $data = $this->request->postMore([
  106. ['bank_code', ''],
  107. ['bank_address', ''],
  108. ['alipay_account', ''],
  109. ['alipay_qrcode_url', ''],
  110. ['wechat', ''],
  111. ['wechat_qrcode_url', '']
  112. ]);
  113. $storeInfo = $this->services->get((int)$this->storeId);
  114. if (!$storeInfo) {
  115. return app('json')->fail('门店不存在');
  116. }
  117. if ($this->services->update($storeInfo['id'], $data)) {
  118. return app('json')->success('设置成功');
  119. } else {
  120. return app('json')->fail('设置失败');
  121. }
  122. }
  123. /**
  124. * 获取uu、达达配送商品类型
  125. * @param $type
  126. * @return mixed
  127. */
  128. public function getBusiness($type = 1)
  129. {
  130. return app('json')->success(DeliverySevices::init((int)$type)->getBusiness());
  131. }
  132. /**获取门店二维码
  133. * @return mixed
  134. */
  135. public function store_qrcode()
  136. {
  137. $id = (int)$this->storeId;
  138. //生成h5地址
  139. $weixinPage = "/pages/store_cate/store_cate?id=" . $id;
  140. $weixinFileName = "wechat_store_cate_id_" . $id . ".png";
  141. /** @var QrcodeServices $QrcodeService */
  142. $QrcodeService = app()->make(QrcodeServices::class);
  143. $wechatQrcode = $QrcodeService->getWechatQrcodePath($weixinFileName, $weixinPage, false, false);
  144. //生成小程序地址
  145. $routineQrcode = $QrcodeService->getRoutineQrcodePath($id, 0, 10, [], true);
  146. $data = ['wechat' => $wechatQrcode, 'routine' => $routineQrcode];
  147. return $this->success($data);
  148. }
  149. }