Merchant.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\system\controller\v1;
  3. use app\BaseController;
  4. use library\services\UtilService;
  5. use app\model\system\Merchant as MerchantModel;
  6. /**
  7. * 商家管理
  8. * Class Merchant
  9. * @package app\system\controller\v1
  10. */
  11. class Merchant extends BaseController
  12. {
  13. /**
  14. * 显示资源列表
  15. *
  16. * @return \think\Response
  17. */
  18. public function index()
  19. {
  20. $where = UtilService::getMore([
  21. ['page', 1],
  22. ['limit', 20],
  23. ['name', '']
  24. ]);
  25. $list = MerchantModel::systemPage($where);
  26. return app('json')->success($list);
  27. }
  28. /**
  29. * 获取所有显示商家(不分页)
  30. */
  31. public function list()
  32. {
  33. $list = MerchantModel::where('is_del', 0)->where('status', 1)->select()->toArray();
  34. return app('json')->success($list);
  35. }
  36. /**
  37. * 详情
  38. * @param $id
  39. * @return mixed
  40. */
  41. public function read($id)
  42. {
  43. $info = MerchantModel::getOne($id);
  44. return app('json')->success(compact('info'));
  45. }
  46. /**
  47. * 保存新建的资源
  48. * @param int $id
  49. */
  50. public function save($id = 0)
  51. {
  52. $data = UtilService::getMore([
  53. ['name','','empty','公司名称不能为空'],
  54. 'main',
  55. 'principal',
  56. 'phone',
  57. ['amount', 0]
  58. ]);
  59. if ($id) {
  60. $record = MerchantModel::get($id);
  61. if (!$record) return app('json')->fail('数据不存在!');
  62. MerchantModel::where('id',$id)->save($data);
  63. return app('json')->success('编辑成功!');
  64. } else {
  65. $data['add_time'] = time();
  66. $id = MerchantModel::insertGetId($data);
  67. MerchantModel::where('id',$id)->save($data);
  68. return app('json')->success('添加商家成功!');
  69. }
  70. }
  71. /**
  72. * 删除指定资源
  73. *
  74. * @param int $id
  75. * @return \think\Response
  76. */
  77. public function delete($id)
  78. {
  79. if (!$id) return app('json')->fail('数据不存在');
  80. $record = MerchantModel::get($id);
  81. if (!$record) return app('json')->fail('数据不存在!');
  82. if ($record['is_del']) return app('json')->fail('已删除!');
  83. $data['is_del'] = 1;
  84. if (!MerchantModel::where('id',$id)->save($data))
  85. return app('json')->fail(MerchantModel::getErrorInfo('删除失败,请稍候再试!'));
  86. else
  87. return app('json')->success('删除成功!');
  88. }
  89. /**
  90. * 修改状态
  91. * @param $id
  92. * @param $status
  93. * @return mixed
  94. */
  95. public function set_status($id, $status)
  96. {
  97. if ($status == '' || $id == 0) return app('json')->fail('参数错误');
  98. MerchantModel::where(['id' => $id])->update(['status' => $status]);
  99. return app('json')->success($status == 0 ? '关闭成功' : '开启成功');
  100. }
  101. }