| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- 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);
- }
- }
|