MemberWalletService.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\MemberPaymentModel;
  13. use App\Models\MemberWalletModel;
  14. use App\Services\BaseService;
  15. /**
  16. * 会员钱包地址簿-服务类
  17. * Class MemberWalletService
  18. * @package App\Services\Api
  19. */
  20. class MemberWalletService extends BaseService
  21. {
  22. // 静态对象
  23. protected static $instance = null;
  24. /**
  25. * 构造函数
  26. * @since 2020/11/10
  27. * LoginService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new MemberWalletModel();
  32. }
  33. /**
  34. * 静态入口
  35. * @return static|null
  36. */
  37. public static function make()
  38. {
  39. if (!self::$instance) {
  40. self::$instance = (new static());
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * 获取选项列表
  46. * @param $userId
  47. * @return mixed
  48. */
  49. public function getOptionList($userId, $type = 1, $pageSize = 15)
  50. {
  51. $pageSize = $type==1? 0 : $pageSize;
  52. $list = $this->model->where(['mark'=>1,'status'=>1,'user_id'=> $userId])
  53. ->paginate($pageSize>0? $pageSize : 9999999);
  54. $list = $list? $list->toArray() :[];
  55. return [
  56. 'pageSize'=> $pageSize,
  57. 'total'=>isset($list['total'])? $list['total'] : 0,
  58. 'list'=> isset($list['data'])? $list['data'] : []
  59. ];
  60. }
  61. /**
  62. * 删除
  63. * @param $id
  64. * @param $userId
  65. * @return mixed
  66. */
  67. public function del($id, $userId){
  68. // 永久删除
  69. $this->model->where(['user_id' => $userId, 'id' => $id,'status'=> 0,'mark'=>1])
  70. ->where('update_time','<', time() - 2 * 86400)
  71. ->delete();
  72. return $this->model->where(['user_id' => $userId, 'id' => $id])->update(['status'=> 0,'mark'=>1]);
  73. }
  74. /**
  75. * 编辑或新增
  76. * @param $id
  77. * @param $params
  78. * @return mixed
  79. */
  80. public function saveData($userId, $params)
  81. {
  82. $address = isset($params['address'])? $params['address'] : '';
  83. $checkId = $address? $this->model->where(['mark'=>1,'address'=>$address])->value('id') : 0;
  84. if($checkId){
  85. $this->error = 2208;
  86. return false;
  87. }
  88. $data = [
  89. 'user_id'=> $userId,
  90. 'name'=> isset($params['name'])? $params['name'] : '用户钱包',
  91. 'remark'=> isset($params['remark'])? $params['remark'] : '',
  92. 'address'=> $address,
  93. 'coin_type'=> isset($params['coin_type'])? intval($params['coin_type']) : 0,
  94. 'status'=> 1,
  95. 'mark'=> 1,
  96. ];
  97. return $this->model->insert($data);
  98. }
  99. }