ShippingTemplates.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\adminapi\controller\v1\setting;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\shipping\ShippingTemplatesServices;
  14. use app\services\shipping\SystemCityServices;
  15. use think\facade\App;
  16. /**
  17. * 运费模板
  18. * Class ShippingTemplates
  19. * @package app\adminapi\controller\v1\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. return app('json')->success($this->services->getShippingList($where));
  44. }
  45. /**
  46. * 修改
  47. * @return string
  48. * @throws \Exception
  49. */
  50. public function edit($id)
  51. {
  52. return app('json')->success($this->services->getShipping((int)$id));
  53. }
  54. /**
  55. * 保存或者修改
  56. * @param int $id
  57. */
  58. public function save($id = 0)
  59. {
  60. $data = $this->request->postMore([
  61. [['region_info', 'a'], []],
  62. [['appoint_info', 'a'], []],
  63. [['sort', 'd'], 0],
  64. [['type', 'd'], 0],
  65. [['name', 's'], ''],
  66. [['appoint', 'd'], 0],
  67. ]);
  68. validate(\app\adminapi\validate\setting\ShippingTemplatesValidate::class)->scene('save')->check($data);
  69. $temp['name'] = $data['name'];
  70. $temp['type'] = $data['type'];
  71. $temp['appoint'] = $data['appoint'];
  72. $temp['sort'] = $data['sort'];
  73. $temp['add_time'] = time();
  74. $this->services->save((int)$id, $temp, $data);
  75. return app('json')->success('添加成功!');
  76. }
  77. /**
  78. * 删除运费模板
  79. */
  80. public function delete()
  81. {
  82. [$id] = $this->request->getMore([
  83. [['id', 'd'], 0],
  84. ], true);
  85. if ($id == 1) {
  86. return app('json')->fail('默认模板不能删除');
  87. } else {
  88. $this->services->detete($id);
  89. return app('json')->success('删除成功');
  90. }
  91. }
  92. /**
  93. * 城市数据
  94. * @return mixed
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\DbException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. */
  99. public function city_list(SystemCityServices $services)
  100. {
  101. return app('json')->success($services->getShippingCity());
  102. }
  103. }