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, '该地址不存在'); } }