TransportextendController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\TransportExtend;
  5. class TransportextendController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $keyword = trim(input('post.keyword', '', 'serach_in'));
  11. $status = trim(input('post.status', '', 'serach_in'));
  12. $where = [];
  13. $where['weid'] = $weid;
  14. if ($status !== '') {
  15. $where['status'] = $status;
  16. }
  17. $field = '*';
  18. $query = TransportExtend::where($where);
  19. if (!empty($keyword)) {
  20. $query->where('title', 'like', '%' . $keyword . '%');
  21. }
  22. $query->field($field)->order('id asc');
  23. $datalist = $query->paginate(getpage())->toArray();
  24. foreach ($datalist['data'] as &$vo) {
  25. if ($vo['is_default'] == 1) {
  26. $vo['area_name'] = '[默认]' . $vo['area_name'];
  27. }
  28. }
  29. $data['data'] = $datalist;
  30. return $this->json($data);
  31. }
  32. function listUpdate()
  33. {
  34. $data = only('id,snum,sprice,xnum,xprice,sort,is_default,status');
  35. if (!$data['id']) throw new ValidateException('参数错误');
  36. TransportExtend::update($data);
  37. return $this->json(['msg' => '操作成功']);
  38. }
  39. public function update()
  40. {
  41. $id = $this->request->post('id');
  42. $data = input('post.');
  43. if(!empty($data['area_id'])){
  44. $data['area_id'] = implode(',', $data['area_id']);
  45. }
  46. if (empty($id)) {
  47. $data['weid'] = weid();
  48. $res = TransportExtend::create($data);
  49. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  50. } else {
  51. TransportExtend::update($data);
  52. return $this->json(['msg' => '修改成功']);
  53. }
  54. }
  55. function getInfo()
  56. {
  57. $id = $this->request->post('id', '', 'serach_in');
  58. if (!$id) $this->error('参数错误');
  59. $res = TransportExtend::find($id);
  60. if (!empty($res)) {
  61. $res = $res->toArray();
  62. }
  63. $res['area_id'] = explode(',',$res['area_id']);
  64. return $this->json(['data' => $res]);
  65. }
  66. function delete()
  67. {
  68. return $this->del(new TransportExtend());
  69. }
  70. }