// +---------------------------------------------------------------------- namespace App\Services\Api; use App\Models\MemberPaymentModel; use App\Models\MemberWalletModel; use App\Services\BaseService; /** * 会员钱包地址簿-服务类 * Class MemberWalletService * @package App\Services\Api */ class MemberWalletService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @since 2020/11/10 * LoginService constructor. */ public function __construct() { $this->model = new MemberWalletModel(); } /** * 静态入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = (new static()); } return self::$instance; } /** * 获取选项列表 * @param $userId * @return mixed */ public function getOptionList($userId, $type = 1, $pageSize = 15) { $pageSize = $type==1? 0 : $pageSize; $list = $this->model->where(['mark'=>1,'status'=>1,'user_id'=> $userId]) ->paginate($pageSize>0? $pageSize : 9999999); $list = $list? $list->toArray() :[]; return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } /** * 删除 * @param $id * @param $userId * @return mixed */ public function del($id, $userId){ // 永久删除 $this->model->where(['user_id' => $userId, 'id' => $id,'status'=> 0,'mark'=>1]) ->where('update_time','<', time() - 2 * 86400) ->delete(); return $this->model->where(['user_id' => $userId, 'id' => $id])->update(['status'=> 0,'mark'=>1]); } /** * 编辑或新增 * @param $id * @param $params * @return mixed */ public function saveData($userId, $params) { $address = isset($params['address'])? $params['address'] : ''; $checkId = $address? $this->model->where(['mark'=>1,'address'=>$address])->value('id') : 0; if($checkId){ $this->error = 2208; return false; } $data = [ 'user_id'=> $userId, 'name'=> isset($params['name'])? $params['name'] : '用户钱包', 'remark'=> isset($params['remark'])? $params['remark'] : '', 'address'=> $address, 'coin_type'=> isset($params['coin_type'])? intval($params['coin_type']) : 0, 'status'=> 1, 'mark'=> 1, ]; return $this->model->insert($data); } }