| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\MemberAddressModel;
- use App\Models\MemberBankModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 用户银行卡管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class MemberBankService
- * @package App\Services\Common
- */
- class MemberBankService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * MemberBankService constructor.
- */
- public function __construct()
- {
- $this->model = new MemberBankModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 列表数据
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1];
- $status = isset($params['status']) ? $params['status'] : 0;
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
- if ($userId > 0) {
- $where['a.user_id'] = $userId;
- }
- $list = $this->model->from('member_bank as a')
- ->where($where)
- ->select(['a.*'])
- ->orderBy('a.is_default', 'asc')
- ->orderBy('a.id', 'desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 添加编辑
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function edit()
- {
- // 请求参数
- $data = request()->all();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- /**
- * 保存数据
- * @param $userId
- * @return mixed
- */
- public function saveData($userId)
- {
- $params = request()->all();
- $id = isset($params['id']) ? $params['id'] : 0;
- $isDefault = isset($params['is_default']) ? $params['is_default'] : 2;
- $data = [
- 'user_id' => $userId,
- 'realname' => isset($params['realname']) ? $params['realname'] : '',
- 'bank_name' => isset($params['bank_name']) ? $params['bank_name'] : '',
- 'bank_num' => isset($params['bank_num']) ? $params['bank_num'] : '',
- 'remark' => isset($params['remark']) ? $params['remark'] : '',
- 'is_default' => $isDefault,
- 'status' => isset($params['status']) ? $params['status'] : 1,
- 'update_time' => time(),
- 'mark' => 1,
- ];
- if($isDefault==1){
- $this->model->where(['user_id'=> $userId])->update(['is_default'=> 2,'update_time'=> time()]);
- }
- RedisService::keyDel("caches:banks:{$userId}");
- if(!$id){
- $data['create_time'] = time();
- return $this->model->insertGetId($data);
- }else{
- return $this->model->where(['id'=> $id])->update($data);
- }
- }
- /**
- * @param $userId
- * @return array|mixed
- */
- public function getBindInfo($userId)
- {
- $cacheKey = "caches:banks:{$userId}";
- $info = RedisService::get($cacheKey);
- if($info){
- return $info;
- }
- $info = $this->model->where(['user_id'=> $userId,'mark'=>1,'status'=>1])
- ->orderBy('is_default','asc')
- ->orderBy('id','desc')
- ->first();
- $info = $info? $info->toArray() : [];
- if($info){
- RedisService::set($cacheKey, $info, rand(5, 10));
- }
- return $info;
- }
- }
|