Merchant.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. ['issuing', 0],
  59. ['packet', 0],
  60. ['hot', 0],
  61. 'advantage'
  62. ]);
  63. if ($id) {
  64. $record = MerchantModel::get($id);
  65. if (!$record) return app('json')->fail('数据不存在!');
  66. MerchantModel::where('id',$id)->save($data);
  67. return app('json')->success('编辑成功!');
  68. } else {
  69. $data['add_time'] = time();
  70. $id = MerchantModel::insertGetId($data);
  71. MerchantModel::where('id',$id)->save($data);
  72. return app('json')->success('添加商家成功!');
  73. }
  74. }
  75. /**
  76. * 删除指定资源
  77. *
  78. * @param int $id
  79. * @return \think\Response
  80. */
  81. public function delete($id)
  82. {
  83. if (!$id) return app('json')->fail('数据不存在');
  84. $record = MerchantModel::get($id);
  85. if (!$record) return app('json')->fail('数据不存在!');
  86. if ($record['is_del']) return app('json')->fail('已删除!');
  87. $data['is_del'] = 1;
  88. if (!MerchantModel::where('id',$id)->save($data))
  89. return app('json')->fail(MerchantModel::getErrorInfo('删除失败,请稍候再试!'));
  90. else
  91. return app('json')->success('删除成功!');
  92. }
  93. /**
  94. * 修改状态
  95. * @param $id
  96. * @param $status
  97. * @return mixed
  98. */
  99. public function set_status($id, $status)
  100. {
  101. if ($status == '' || $id == 0) return app('json')->fail('参数错误');
  102. MerchantModel::where(['id' => $id])->update(['status' => $status]);
  103. return app('json')->success($status == 0 ? '关闭成功' : '开启成功');
  104. }
  105. }