ShippingTemplates.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\product\shipping;
  12. use app\controller\store\AuthController;
  13. use app\services\product\shipping\ShippingTemplatesServices;
  14. use app\services\other\SystemCityServices;
  15. use think\facade\App;
  16. /**
  17. * 运费模板
  18. * Class ShippingTemplates
  19. * @package app\controller\store\setting
  20. */
  21. class ShippingTemplates extends AuthController
  22. {
  23. /**
  24. * 构造方法
  25. * ShippingTemplates constructor.
  26. * @param App $app
  27. * @param ShippingTemplatesServices $services
  28. */
  29. public function __construct(App $app, ShippingTemplatesServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 运费模板列表
  36. * @return mixed
  37. */
  38. public function temp_list()
  39. {
  40. $where = $this->request->getMore([
  41. [['name', 's'], '']
  42. ]);
  43. $where['type'] = 1;
  44. $where['relation_id'] = $this->storeId;
  45. return $this->success($this->services->getShippingList($where));
  46. }
  47. /**
  48. * 修改
  49. * @return string
  50. * @throws \Exception
  51. */
  52. public function edit($id)
  53. {
  54. return $this->success($this->services->getShipping((int)$id));
  55. }
  56. /**
  57. * 保存或者修改
  58. * @param int $id
  59. */
  60. public function save($id = 0)
  61. {
  62. $data = $this->request->postMore([
  63. [['region_info', 'a'], []],
  64. [['appoint_info', 'a'], []],
  65. [['no_delivery_info', 'a'], []],
  66. [['sort', 'd'], 0],
  67. [['type', 'd'], 0, '', 'group'],
  68. [['name', 's'], ''],
  69. [['appoint', 'd'], 0],
  70. [['no_delivery', 'd'], 0]
  71. ]);
  72. $this->validate($data, \app\validate\admin\setting\ShippingTemplatesValidate::class, 'save');
  73. $temp['type'] = 1;
  74. $temp['relation_id'] = $this->storeId;
  75. $temp['name'] = $data['name'];
  76. $temp['group'] = $data['group'];
  77. $temp['appoint'] = $data['appoint'] && $data['appoint_info'] ? 1 : 0;
  78. $temp['no_delivery'] = $data['no_delivery'] && $data['no_delivery_info'] ? 1 : 0;
  79. $temp['sort'] = $data['sort'];
  80. $temp['add_time'] = time();
  81. $this->services->save((int)$id, $temp, $data);
  82. event('product.shipping.update');
  83. return $this->success((int)$id ? '修改成功!' : '添加成功!');
  84. }
  85. /**
  86. * 删除运费模板
  87. */
  88. public function delete()
  89. {
  90. [$id] = $this->request->getMore([
  91. [['id', 'd'], 0],
  92. ], true);
  93. if ($id == 1) {
  94. return $this->fail('默认模板不能删除');
  95. } else {
  96. $this->services->detete($id);
  97. event('product.shipping.update');
  98. return $this->success('删除成功');
  99. }
  100. }
  101. /**
  102. * 城市数据
  103. * @return mixed
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\DbException
  106. * @throws \think\db\exception\ModelNotFoundException
  107. */
  108. public function city_list(SystemCityServices $services)
  109. {
  110. return $this->success($services->getShippingCity());
  111. }
  112. }