ShippingTemplates.php 3.6 KB

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