123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace app\mobile\logic;
- use app\model\AddrModel;
- use app\model\CommonModel;
- use think\response\Json;
- class AddrLogic extends BaseLogic
- {
- //列表
- public static function list(array $data = []): Json
- {
- $db = AddrModel::where('is_del', CommonModel::$del_normal);
- $count = $db->count('id');
- $list = $db
- ->field('id,addr_code,addr,contactor,mobile,"" addr_name')
- ->page($data['page'], $data['size'])
- ->withAttr('addr_code', function ($val) {
- return explode(',', $val);
- })->withAttr('addr_name', function ($val, $da) {
- return get_addr_name_array($da['addr_code']);
- })
- ->order('id', 'desc')
- ->select()
- ->toArray();
- return json_show(CommonModel::$success, '获取列表成功', ['count' => $count, 'list' => $list]);
- }
- //添加
- public static function add(array $data = []): Json
- {
- $rs = AddrModel::create(array_merge($data, [
- 'uid' => self::$aid,
- 'addr_code' => implode(',', $data['addr_code']),
- 'is_del' => CommonModel::$del_normal,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- ]))->save();
- return $rs ? json_show(CommonModel::$success, '添加地址成功') : json_show(CommonModel::$error_param, '添加地址失败');
- }
- //详情
- public static function read(int $id = 0): Json
- {
- $rs = AddrModel::withoutField('uid,is_del')
- ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
- ->append(['addr_name'])
- ->withAttr('addr_code', function ($val) {
- return explode(',', $val);
- })->withAttr('addr_name', function ($val, $da) {
- return get_addr_name_array($da['addr_code']);
- })
- ->findOrEmpty()
- ->toArray();
- return json_show(CommonModel::$success, '获取收货地址详情成功', $rs);
- }
- //修改
- public static function edit(array $data = []): Json
- {
- $res = AddrModel::field('id')
- ->where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
- ->findOrEmpty()
- ->isEmpty();
- if ($res) return json_show(CommonModel::$error_param, '该地址不存在');
- $rs = AddrModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
- ->save(array_merge($data, [
- 'addr_code' => implode(',', $data['addr_code']),
- 'updatetime' => date('Y-m-d H:i:s'),
- ]));
- return $rs ? json_show(CommonModel::$success, '修改地址成功') : json_show(CommonModel::$error_param, '修改地址失败');
- }
- //删除
- public static function delete(int $id = 0): Json
- {
- $rs = AddrModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
- ->save([
- 'is_del' => CommonModel::$del_deleted,
- 'updatetime' => date('Y-m-d H:i:s'),
- ]);
- return $rs ? json_show(CommonModel::$success, '删除地址成功') : json_show(CommonModel::$error_param, '该地址不存在');
- }
- }
|