Merchant.php 2.9 KB

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