123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\system\controller\v1;
- use app\BaseController;
- use library\services\UtilService;
- use app\model\system\Merchant as MerchantModel;
- class Merchant extends BaseController
- {
-
- public function index()
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ['name', ''],
- ['main', '']
- ]);
- $list = MerchantModel::systemPage($where);
- return app('json')->success($list);
- }
-
- public function list()
- {
- $list = MerchantModel::where('is_del', 0)->where('status', 1)->select()->toArray();
- return app('json')->success($list);
- }
-
- public function read($id)
- {
- $info = MerchantModel::getOne($id);
- return app('json')->success(compact('info'));
- }
-
- public function save($id = 0)
- {
- $data = UtilService::getMore([
- ['name','','empty','公司名称不能为空'],
- 'main',
- 'principal',
- 'phone',
- ['amount', 0]
- ]);
- if ($id) {
- $record = MerchantModel::get($id);
- if (!$record) return app('json')->fail('数据不存在!');
- MerchantModel::where('id',$id)->save($data);
- return app('json')->success('编辑成功!');
- } else {
- $data['add_time'] = time();
- $id = MerchantModel::insertGetId($data);
- MerchantModel::where('id',$id)->save($data);
- return app('json')->success('添加商家成功!');
- }
- }
-
- public function delete($id)
- {
- if (!$id) return app('json')->fail('数据不存在');
- $record = MerchantModel::get($id);
- if (!$record) return app('json')->fail('数据不存在!');
- if ($record['is_del']) return app('json')->fail('已删除!');
- $data['is_del'] = 1;
- if (!MerchantModel::where('id',$id)->save($data))
- return app('json')->fail(MerchantModel::getErrorInfo('删除失败,请稍候再试!'));
- else
- return app('json')->success('删除成功!');
- }
-
- public function set_status($id, $status)
- {
- if ($status == '' || $id == 0) return app('json')->fail('参数错误');
- MerchantModel::where(['id' => $id])->update(['status' => $status]);
- return app('json')->success($status == 0 ? '关闭成功' : '开启成功');
- }
- }
|