Bläddra i källkod

wes 多宝福袋 0306合并

APPLE 3 år sedan
förälder
incheckning
ed73d12e15

+ 13 - 0
app/common/model/ExpressShippingMethodModel.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * 运费模板
+ */
+namespace app\common\model;
+
+
+use think\Model;
+
+class ExpressShippingMethodModel extends Model
+{
+    protected $name = "express_shipping_method";
+}

+ 16 - 0
app/common/model/UserBankSignModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 用户签约银行卡
+ * Class UserBankSignModel
+ * @package app\common\model
+ */
+class UserBankSignModel extends Model
+{
+
+    protected $name = 'user_bank_sign';
+}

+ 16 - 0
app/common/model/UserMessageModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 用户通知消息
+ * Class UserMessageModel
+ * @package app\common\model
+ */
+class UserMessageModel extends Model
+{
+
+    protected $name = 'user_message';
+}

+ 16 - 0
app/common/model/YsBankListModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 银盛银行卡
+ * Class YsBankListModel
+ * @package app\common\model
+ */
+class YsBankListModel extends Model
+{
+
+    protected $name = 'ys_banklist';
+}

+ 38 - 0
app/common/service/BoxHandleService.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\BoxHandleModel;
+use utils\RedisCache;
+
+/**
+ * 开出盒子服务 by wes
+ * Class BoxHandleService
+ * @package app\common\service
+ */
+class BoxHandleService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new BoxHandleModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+
+}

+ 37 - 0
app/common/service/BoxMidHandleService.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\BoxMidHandleModel;
+use utils\RedisCache;
+
+/**
+ * 盒子匹配服务 by wes
+ * Class BoxMidHandleService
+ * @package app\common\service
+ */
+class BoxMidHandleService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new BoxMidHandleModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+}

+ 36 - 0
app/common/service/BoxRecordService.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\BoxRecordModel;
+use utils\RedisCache;
+
+/**
+ * 盒子预约记录服务 by wes
+ * Class BoxRecordService
+ * @package app\common\service
+ */
+class BoxRecordService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new BoxRecordModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+}

+ 37 - 0
app/common/service/BoxService.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\BoxModel;
+use utils\RedisCache;
+
+/**
+ * 盒子期数服务 by wes
+ * Class BoxService
+ * @package app\common\service
+ */
+class BoxService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new BoxModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+}

+ 67 - 0
app/common/service/ExpressShippingMethodService.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\ExpressShippingMethodModel;
+use utils\RedisCache;
+
+/**
+ * 配送费模板列表服务 by wes
+ * Class ExpressShippingMethodService
+ * @package app\common\service
+ */
+class ExpressShippingMethodService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new ExpressShippingMethodModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 获取模板列表
+     * @param $templateId 模板ID
+     * @param bool $cache 是否缓存
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getListByTemplate($templateId, $cache=true)
+    {
+        if($templateId<=0){
+            return false;
+        }
+
+        $cacheKey = "caches:shippingList:template_{$templateId}";
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+        $where = ['template_id'=> $templateId];
+        $data = $this->model->where($where)->select();
+        $data = $data? $data->toArray():[];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, rand(10,20));
+        }
+
+        return $data;
+    }
+
+
+}

+ 37 - 0
app/common/service/MoneyLogService.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\MoneyLogModel;
+use utils\RedisCache;
+
+/**
+ * 余额流水服务 by wes
+ * Class MoneyLogService
+ * @package app\common\service
+ */
+class MoneyLogService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new MoneyLogModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+}

+ 60 - 0
app/common/service/PayConfigService.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\PayConfigModel;
+use utils\RedisCache;
+
+/**
+ * 支付配置服务 by wes
+ * Class PayConfigService
+ * @package app\common\service
+ */
+class PayConfigService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new PayConfigModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 按渠道获取支付配置参数
+     * @param $channel 渠道
+     * @param string $field
+     * @param bool $cache
+     * @return array|mixed
+     */
+    public function getInfoByChannel($channel, $field='', $cache=true)
+    {
+        $cacheKey = "caches:temp:payConfig:channel_{$channel}".($field? '_'.md5($field):'');
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+
+        $field = $field? $field : 'app_id,private_key,public_key,app_cert_path,pay_root_cert,pay_cert_path,mchid';
+        $data = $this->model->where(['channel'=> $channel,'status'=>1])->field($field)->findOrEmpty();
+        $data = $data? $data->toArray() : [];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, 7200);
+        }
+
+        return $data;
+    }
+}

+ 124 - 0
app/common/service/PaymentService.php

@@ -0,0 +1,124 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\PaymentModel;
+use utils\RedisCache;
+
+/**
+ * 支付服务 by wes
+ * Class PaymentService
+ * @package app\common\service
+ */
+class PaymentService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new PaymentModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 按状态获取支付单数量
+     * @param $uid
+     * @param $orderType
+     * @param $state
+     * @param int $time 时间/小时,默认2小时
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getPaymentCountByState($uid, $orderSn='', $orderType, $state, $time = 2)
+    {
+        $cacheKey = "caches:paymentCall:u{$uid}_ot{$orderType}_s{$state}_{$time}_{$orderSn}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $where = [];
+        if($orderType){
+            $where['order_type'] = $orderType;
+        }
+
+        if($state){
+            $where['state'] = $state;
+        }
+
+        $data = $this->model->where($where)->where(function ($query) use($time,$orderSn){
+            if($time>0){
+                $query->where('creat_at','>=', time() - $time * 3600);
+            }
+            if($orderSn){
+                $query->where('remarks',$orderSn);
+            }
+        })->count('id');
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 验证订单是否已支付
+     * @param $uid
+     * @param $orderSn
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function checkPaymentState($uid, $orderSn)
+    {
+        $cacheKey = "caches:paymentState:u{$uid}_sn{$orderSn}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $data = $this->model->where(['state'=> 6])->where(function ($query) use($orderSn){
+            if($orderSn){
+                $query->where('remarks', $orderSn);
+            }
+        })->value('id');
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(2,3));
+        }
+
+        return $data;
+    }
+
+    public function getCacheInfo($outTradeNo, $state=7, $field='')
+    {
+        $cacheKey = "caches:payment:info:otn{$outTradeNo}_{$state}".($field? '_'.md5($field):'');
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $field = $field? $field : 'id,out_trade_no,uid,state,trade_type,out_trade_no1,hy_token_id,syl_sureorderid,hy_bill_no,is_retreat,pay_way,order_type,sid,remarks,trade_no';
+        $data = $this->model->where(['out_trade_no'=> $outTradeNo,'state'=> $state])
+            ->field($field)
+            ->value('id');
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
+}

+ 37 - 0
app/common/service/ProfitLogService.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\UserUnmoneyModel;
+use utils\RedisCache;
+
+/**
+ * 用户利润记录服务 by wes
+ * Class ProfitLogService
+ * @package app\common\service
+ */
+class ProfitLogService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new UserUnmoneyModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+}

+ 37 - 0
app/common/service/ScoreLogService.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\ScoreLogModel;
+use utils\RedisCache;
+
+/**
+ * 积分流水服务 by wes
+ * Class ScoreLogService
+ * @package app\common\service
+ */
+class ScoreLogService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new ScoreLogModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+}

+ 66 - 0
app/common/service/ShopOrderGoodsService.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\ShopOrderGoods;
+use utils\RedisCache;
+
+/**
+ * 订单商品服务 by wes
+ * Class ShopOrderGoodsService
+ * @package app\common\service
+ */
+class ShopOrderGoodsService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new ShopOrderGoods();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 用户购买过该商品的数量统计
+     * @param $uid 用户ID
+     * @param int $goodsId 商品ID,0表示用户购买的所有商品数量统计
+     * @return array|mixed
+     */
+    public function getCountByUserAndGoods($uid, $goodsSn='0')
+    {
+        $cacheKey = "caches:orders:goodsCount:{$uid}_{$goodsSn}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $where = ['og.uid'=>$uid];
+        if($goodsSn){
+            $where['g.goods_sn'] = $goodsSn;
+        }
+        $data = $this->model->alias('og')
+                ->leftJoin('shop_order o', 'o.order_id = og.order_id')
+                ->leftJoin('shop_goods g', 'og.goods_id = g.goods_id')
+                ->where('o.status', 'in', [1, 2, 4])
+                ->where($where)
+                ->count('og.og_id');
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+}

+ 693 - 0
app/common/service/ShopOrderService.php

@@ -0,0 +1,693 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\ShopCartModel;
+use app\common\model\ShopGoods;
+use app\common\model\ShopGoodsModel;
+use app\common\model\ShopGoodsSpec;
+use app\common\model\ShopOrder;
+use app\common\model\ShopOrderGoodsModel;
+use app\common\model\ShopOrderShippingModel;
+use app\common\model\UserAddressModel;
+use jobs\ShopOrderJob;
+use think\Exception;
+use think\facade\Db;
+use utils\Queue;
+use utils\RedisCache;
+
+/**
+ * 商城订单服务 by wes
+ * Class ShopOrderService
+ * @package app\common\service
+ */
+class ShopOrderService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new ShopOrder();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 商城下单
+     * @param $uid 用户ID
+     * @param $buyGoods 购买的商品数组
+     * @param $payType 支付方式
+     * @param $request 请求数据
+     * @param int $cartIds 购物车ID数组
+     * @param int $cls 赠送月卡功能开关
+     * @return array
+     * @throws Exception
+     */
+    public function createOrder($uid, $buyGoods, $payType, $request, $cartIds = 0, $cls = 0)
+    {
+        // 获取收货地址信息
+        $orderType = 1;   //  订单类型 1商城订单 2积分订单 3.兑换券 4.锁定积分兑换 5.福袋发货订单
+        $addressId = $request->post('address', '');
+        $remark = $request->post('order_remark', '');
+        if (!$addressId || !$userAddress = UserAddressModel::getAddressIdDetails((int)$addressId)) {
+            throw new Exception('获取收货地址失败');
+        }
+
+        $addressUid = isset($userAddress['uid']) ? $userAddress['uid'] : 0;
+        if ($addressUid != $uid) {
+            throw new Exception('收货地址信息异常');
+        }
+
+        if (empty($buyGoods)) {
+            throw new Exception('商品参数错误');
+        }
+
+        // 未支付订单数量验证
+        $count = ShopOrderService::make()->checkBuyCountByTime($uid, 1, 0);
+        $noPayLimit = env('common.ORDER_NO_PAY_LIMIT', 5);
+        if ($count >= $noPayLimit) {
+            throw new Exception("2小时内未支付的订单不能超过{$noPayLimit}个,下单失败");
+        }
+
+        // 订单商品数据处理
+        $i = 0;
+        $nowTime = time();
+        $orderId = $this->model->max('order_id') + 1;
+        $orderDatas = $orderGoods = $orders = $shippingList = [];
+        $expireTime = time() + intval(env('common.ORDER_EXPIRES_TIME'));
+        Db::startTrans();
+        try {
+            foreach ($buyGoods as $k => $v) {
+                $goodsSn = isset($v['goods_sn']) ? trim($v['goods_sn']) : 0;
+                $specId = isset($v['spec_id']) ? trim($v['spec_id']) : 0;
+                $num = isset($v['num']) ? intval($v['num']) : 0;
+                if ($num < 1) {
+                    throw new Exception('请先选择商品数量哦');
+                }
+
+                // 商品信息验证
+                $goodsInfo = ShopGoodsService::make()->getCacheInfo($v['goods_sn']);
+                if (!$goodsInfo) {
+                    throw new Exception('商品参数错误或已下架,请返回刷新列表');
+                }
+                if ($goodsInfo['goods_type'] == 2) {
+                    throw new Exception('商福袋商品不能购买');
+                }
+
+                // 商品限购验证
+                if ($goodsInfo['restrictions_num'] > 0) {
+                    $count = ShopOrderGoodsService::make()->getCountByUserAndGoods($uid, $goodsSn);
+
+                    if ($count > $goodsInfo['restrictions_num']) {
+                        throw new Exception('超过限购');
+                    }
+                    if ($v['num'] + $count > $goodsInfo['restrictions_num']) {
+                        throw new Exception('超过限购数量,还可购买:' . ($goodsInfo['restrictions_num'] - $count) . '件');
+                    }
+                }
+
+                // 商品库存验证
+                if ($goodsSn && $specId && $num > 0) {
+                    $stock = ShopGoodsSpecService::make()->getStock($goodsSn, $specId);
+                    if ($num > $stock) {
+                        throw new Exception('下单失败,所选商品含有库存不足的商品:SN-' . $goodsSn);
+                    }
+                }
+
+                // 是否赠送月卡
+                $giveVip = 0;
+                $goodsGiveVip = isset($goodsInfo['give_vip']) ? $goodsInfo['give_vip'] : 0;
+                if ($cls == 1 && $goodsGiveVip) {
+                    $giveVip = $goodsGiveVip;
+                }
+
+                // 同商品订单数据
+                if (!isset($orderDatas[$goodsSn]) || empty($orderDatas[$goodsSn])) {
+                    $orderSn = createdOrderSn();
+                    $orders[] = $orderSn;
+                    $orderId = $orderId + $i;
+                    $orderDatas[$goodsSn] = [
+                        'order_id' => $orderId,
+                        'order_sn' => $orderSn,
+                        'total_price' => 0,
+                        'payment' => 0,
+                        'user_id' => $uid,
+                        'status' => 0, // 待付款
+                        'ship_postfee' => 0,
+                        'rebate_score' => 0, //总返利积分
+                        'created_time' => date('Y-m-d H:i:s', $nowTime + $i),
+                        'updated_time' => date('Y-m-d H:i:s', $nowTime + $i),
+                        'give_vip' => $giveVip,
+                        'order_remark' => $remark,
+                        'pay_type' => $payType,
+                        'order_type' => $orderType,
+                        'coupon_number' => '',
+                        'expires_time' => sr_getcurtime($expireTime + $i),
+                        'supplier_name' => isset($goodsInfo['supplier_name']) ? $goodsInfo['supplier_name'] : '',
+                    ];
+
+                    // 构建订单配送数据
+                    $shippingList[$orderSn] = [
+                        'order_id' => $orderId,
+                        'sp_name' => $userAddress['name'],
+                        'sp_mobile' => $userAddress['mobile'],
+                        'sp_province' => $userAddress['sp_province'],
+                        'sp_city' => $userAddress['sp_city'],
+                        'sp_county' => $userAddress['sp_county'],
+                        'sp_remark' => $userAddress['remark'],
+                        'sp_mergename' => $userAddress['mergename'],
+                        'created_time' => date('Y-m-d H:i:s', $nowTime + $i),
+                        'updated_time' => date('Y-m-d H:i:s', $nowTime + $i),
+                    ];
+
+                    $i++;
+                }
+
+
+                // 订单商品规格数据
+                $goodsSpec = ShopGoodsSpecService::make()->getDataByGoods($goodsInfo['goods_id'], $specId);
+                $goodsSpecId = isset($goodsSpec['goods_spec_id']) ? $goodsSpec['goods_spec_id'] : 0;
+                $weight = isset($goodsSpec['weight']) ? $goodsSpec['weight'] : 0;
+                $price = isset($goodsSpec['price']) ? $goodsSpec['price'] : 0;
+
+                // 同一个商品数据合计
+                $totalFee = bcmul($num, $price, 3);
+                $totalWeight = bcmul($num, $weight, 3);
+                $orderDatas[$goodsSn]['total_weight'] = isset($orderDatas[$goodsSn]['total_weight']) ? bcadd($orderDatas[$goodsSn]['total_weight'], $totalWeight, 3) : $totalWeight;
+                $orderDatas[$goodsSn]['total_price'] = isset($orderDatas[$goodsSn]['total_price']) ? bcadd($orderDatas[$goodsSn]['total_price'], $totalFee, 3) : $totalFee;
+                $orderDatas[$goodsSn]['num'] = isset($orderDatas[$goodsSn]['num']) ? intval($orderDatas[$goodsSn]['num'] + $num) : $num;
+
+                // 返还积分/金额合计
+                $rebateScore = isset($goodsInfo['rebate_score']) ? bcmul($num, $goodsInfo['rebate_score'], 3) : 0;
+                $rebateMoney = isset($goodsInfo['rebate_money']) ? bcmul($num, $goodsInfo['rebate_money'], 3) : 0;
+                $orderDatas[$goodsSn]['rebate_score'] = isset($orderDatas[$goodsSn]['rebate_score']) ? bcadd($orderDatas[$goodsSn]['rebate_score'], $rebateScore, 3) : $rebateScore;
+                $orderDatas[$goodsSn]['rebate_money'] = isset($orderDatas[$goodsSn]['rebate_money']) ? bcadd($orderDatas[$goodsSn]['rebate_money'], $rebateScore, 3) : $rebateMoney;
+                $orderDatas[$goodsSn]['rebate_money'] = 0;  // 临时覆盖值
+
+                // 邮费计算合计
+                $postFee = 0;
+                $costPostFee = true;
+                if ($costPostFee) {
+                    $city = isset($userAddress['city']) ? $userAddress['city'] : '';
+                    $postData = [
+                        'goods_sn' => $goodsInfo['goods_sn'],
+                        'num' => $orderDatas[$goodsSn]['num'],
+                        'total_price' => $orderDatas[$goodsSn]['total_price'],
+                        'total_weight' => $orderDatas[$goodsSn]['total_weight'],
+                    ];
+                    $postTemplateId = isset($goodsInfo['post_template_id']) ? $goodsInfo['post_template_id'] : 0;
+                    $postFee = ShopOrderService::make()->postFee($city, $postData, $postTemplateId);  // 邮费
+                }
+
+                $orderDatas[$goodsSn]['ship_postfee'] = $postFee;
+                $orderDatas[$goodsSn]['payment'] = bcadd($orderDatas[$goodsSn]['total_price'], $postFee, 3);
+
+                // 订单商品
+                $orderGoods[] = [
+                    'order_id' => $orderDatas[$goodsSn]['order_id'],
+                    'goods_id' => $goodsInfo['goods_id'],
+                    'goods_name' => $goodsInfo['goods_name'],
+                    'goods_category' => $goodsInfo['category'],
+                    'goods_img' => isset($goodsSpec['picture']) && $goodsSpec['picture'] ? $goodsSpec['picture'] : $goodsInfo['goods_img'],
+                    'num' => $num,
+                    'price' => $price,
+                    'total_fee' => $totalFee,
+                    'goods_spec_id' => $goodsSpecId,
+                    'spec_ids' => isset($goodsSpec['spec_ids']) ? $goodsSpec['spec_ids'] : '',
+                    'spec_text' => isset($goodsSpec['spec_text']) ? $goodsSpec['spec_text'] : '',
+                    'rebate_score' => isset($goodsSpec['rebate_score']) ? $goodsSpec['rebate_score'] : 0,
+                    'total_rebate_score' => $orderDatas[$goodsSn]['rebate_score'],
+                    'uid' => $uid
+                ];
+
+                // 扣库存
+                if (!ShopGoodsSpec::where(['goods_spec_id' => $goodsSpecId])->dec('stock', $num)->update()) {
+                    throw new Exception('商品库存处理失败');
+                }
+
+                // 扣除商品总库存
+                if (!ShopGoods::where(['goods_id' => $goodsInfo['goods_id']])->dec('inventory', $num)->update()) {
+                    throw new Exception('商品库存处理失败');
+                }
+
+                // 增加销量
+                if (in_array($orderType, [3, 4, 5])) {
+                    if (!ShopGoodsModel::where(['goods_id' => $goodsInfo['goods_id']])
+                        ->inc('sales_volume', $num)
+                        ->inc('real_sales_volume', $num)
+                        ->update()) {
+                        throw new Exception('商品销量处理失败');
+                    }
+                }
+
+                // 清除商品相关实时数据缓存
+                RedisCache::keyDel('caches:goods:list_*');
+                RedisCache::keyDel('caches:goodsSpec:list_*');
+
+            }
+
+            if (empty($orders) || empty($orderGoods)) {
+                throw new Exception('订单数据错误,下单失败');
+            }
+
+            // 批量写入订单数据
+            $data = array_values($orderDatas);
+            if (!$this->model->insertAll($data)) {
+                Db::rollback();
+                throw new Exception('下单失败');
+            }
+
+            // 批量写入订单商品数据
+            $data = array_values($orderGoods);
+            if (!ShopOrderGoodsModel::insertAll($data)) {
+                Db::rollback();
+                throw new Exception('下单失败,订单商品处理错误');
+            }
+
+            // 写入配送单数据
+            $data = array_values($shippingList);
+            if (!ShopOrderShippingModel::insertAll($data)) {
+                Db::rollback();
+                throw new Exception('下单失败,订单配送数据处理错误');
+            }
+
+            // 超时过期订单队列任务处理
+            if (in_array($orderType, [1, 3]) && $orders) {
+                $ex_time = intval(env('common.ORDER_EXPIRES_TIME', 60 * 60));
+                Queue::instance()->log('订单过期执行成功')
+                    ->job(ShopOrderJob::class)
+                    ->do('ShopOrderExpired')
+                    ->secs($ex_time)
+                    ->push([$orders[0]]);
+            }
+
+            // 验证检查购物车数据
+            if ($cartIds && is_array($cartIds)) {
+                ShopCartModel::where('id', 'in', $cartIds)->where(['user_id' => $uid])->delete();
+            }
+
+            // 清除单一购物车数据
+            $cartId = $request->post('cart_id', 0);
+            if ($cartId) {
+                ShopCartModel::where('id', $cartId)->delete();
+            }
+
+            $cacheKey = "caches:orders:u_{$uid}_{$orderType}:create_{$payType}_" . date('YmdHis') . rand(10, 99);
+            RedisCache::set($cacheKey, ['uid' => $uid, 'orderDatas' => $orderDatas, 'shipping' => $shippingList, 'orderGoods' => $orderGoods, 'post' => $request->post()], 7200);
+
+            Db::commit();
+            return $orders;
+        } catch (\Exception $e) {
+            throw new Exception($e->getMessage());
+        }
+    }
+
+    /**
+     * 下单数据
+     * @param $buyGoods 购买商品
+     * @param $request
+     * @return array
+     * @throws Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function buyDetail($buyGoods, $request)
+    {
+        $addressId = $request->post('address_id', 0);
+        if (!$address = UserAddressModel::getAddressIdDetails($addressId, $request->uid, 1)) {
+            throw new Exception('订单地址错误');
+        }
+
+        $details = $goodsSnArr = [];
+        $paymentTotal = 0;  // 总订单金额
+        $totalRebateScore = 0;  // 总返还积分
+        $totalNum = 0;  // 商品总数量
+        $curXzmoney = SystemConfigService::make()->getConfigByName('xz_cur_money', '', 'xzconfig');
+        foreach ($buyGoods as $k => $v) {
+            $goodsSn = isset($v['goods_sn']) ? $v['goods_sn'] : '';
+            $specId = isset($v['spec_id']) ? $v['spec_id'] : 0;
+            $num = isset($v['num']) ? intval($v['num']) : 0;
+            $totalNum += $num;
+            if ($num <= 0) {
+                throw new Exception('下单失败,请先选择商品数量');
+            }
+
+            // 商品信息
+            if (!$goodsSn || !$goodsInfo = ShopGoodsService::make()->getCacheInfo($goodsSn)) {
+                throw new Exception('下单失败,商品参数错误');
+            }
+
+            // 订单商品规格数据
+            $goodsSnArr[] = $goodsSn;
+            $goodsSpec = ShopGoodsSpecService::make()->getDataByGoods($goodsInfo['goods_id'], $specId);
+            $weight = isset($goodsSpec['weight']) ? $goodsSpec['weight'] : 0;
+            $price = isset($goodsSpec['price']) ? $goodsSpec['price'] : 0;
+            if (empty($goodsSpec)) {
+                throw new Exception('下单失败,存在无效商品');
+            }
+
+            // 商品数据
+            $postFee = '0.00';
+            $rebateScore = bcmul($num, $goodsSpec['rebate_score'], 2);
+            $totalFee = bcmul($num, $price, 2);
+            $totalWeight = bcmul($num, $weight, 3);
+
+            // 组装订单商品数据
+            $details[$goodsSn]['total_rebate_score'] = isset($details[$goodsSn]['total_rebate_score']) ? bcadd($details[$goodsSn]['total_rebate_score'], $rebateScore, 3) : $rebateScore; //总返利积分
+            $details[$goodsSn]['total_num'] = isset($details[$goodsSn]['total_num']) ? bcadd($details[$goodsSn]['total_num'], $num, 3) : $num; //总数量
+            $details[$goodsSn]['total_price'] = isset($details[$goodsSn]['total_price']) ? bcadd($details[$goodsSn]['total_price'], $totalFee, 3) : $totalFee; // 总金额
+            $details[$goodsSn]['total_weight'] = isset($details[$goodsSn]['total_weight']) ? bcadd($details[$goodsSn]['total_weight'], $totalWeight, 3) : $totalWeight; // 总重量
+            $details[$goodsSn]['post_fee'] = $postFee;
+            $details[$goodsSn]['payment'] = bcadd($details[$goodsSn]['total_price'], $details[$goodsSn]['post_fee'], 2);
+            $details[$goodsSn]['supplier_name'] = $goodsInfo['supplier_name'];
+
+            $goodsName = isset($goodsInfo['goods_name']) ? $goodsInfo['goods_name'] : '';
+            $goodsName = $goodsName ? str_replace(' ', '', $goodsName) : '';
+            $goodsName = mb_strlen($goodsName, 'utf-8') > 20 ? mb_substr($goodsName, 0, 19, 'utf-8') : $goodsName;
+            $goodsType = isset($goodsInfo['goods_type']) ? $goodsInfo['goods_type'] : 0;
+            if ($goodsType == 5) {
+                $price = getXzPirceWithPrice($curXzmoney, $price);
+                $totalFee = getXzPirceWithPrice($curXzmoney, $totalFee);
+            }
+            $goods = [
+                'goods_sn' => $goodsInfo['goods_sn'],
+                'goods_id' => $goodsInfo['goods_id'],
+                'goods_type' => $goodsType,
+                'goods_name' => $goodsName,
+                'picture' => $goodsSpec['picture'] ?: $goodsInfo['goods_img'],
+                'num' => $num, //数量
+                'price' => $price,//单价
+                'weight' => $goodsSpec['weight'], //重量
+                'total_fee' => $totalFee, //总价
+                'rebate_score' => $goodsSpec['rebate_score'],//单个返利积分
+                'total_items_rebate_score' => $rebateScore,//总返利积分
+                'spec_ids' => $goodsSpec['spec_ids'],
+                'spec_text' => $goodsSpec['spec_text'],
+                'post_template_id' => $goodsInfo['post_template_id'], //是否包邮,否就是运费模板ID
+                'stock' => $goodsSpec['stock'],
+                'supplier_name' => $goodsInfo['supplier_name']
+            ];
+
+            // 参数合计
+            $totalNum += $num;
+            $paymentTotal += bcadd($totalFee, $postFee, 3);
+            $totalRebateScore = bcadd($totalRebateScore, $rebateScore, 3);
+            $details[$goodsSn]['goods'][] = $goods;
+
+        }
+
+        $total = [
+            'count_payment' => sprintf("%.2f", $paymentTotal),
+            'count_rebate_score' => $totalRebateScore,
+            'count_num' => $totalNum,
+        ];
+
+        return ['address' => $address, 'buyDetail' => array_values($details), 'total' => $total];
+    }
+
+    /**
+     * 取消订单
+     */
+    public function cancelOrder($data, $userId)
+    {
+        $nowTime = date('Y-m-d H:i:s', time());
+        $data = $this->model->where(['order_sn' => $data['order_sn'], 'user_id' => $userId])->field('order_id,status,order_sn')->findOrEmpty();
+        if (empty($data)) {
+            throw new Exception('参数错误');
+        }
+        if ($data['status'] != 0) {
+            throw new Exception('订单状态错误');
+        }
+
+        Db::startTrans();
+        if (!$this->model->where(['order_sn' => $data['order_sn']])->save(['status' => 3, 'updated_time' => $nowTime])) {
+            Db::rollback();
+            throw new Exception('取消失败');
+        }
+
+        $updateStock = $this->model->alias('a')->where(['a.order_sn' => $data['order_sn'], 'a.user_id' => $userId])
+            ->leftJoin('shop_order_goods og', 'og.order_id=a.order_id')
+            ->leftJoin('shop_goods_spec gs', 'gs.goods_spec_id=og.goods_spec_id')
+            ->leftJoin('shop_goods g', 'g.goods_id=og.goods_id')
+            ->update([
+                'g.inventory'=> Db::raw('g.inventory + og.num'),
+                'gs.stock'=> Db::raw('gs.stock + og.num'),
+            ]);
+        if (!$updateStock) {
+            Db::rollback();
+            throw new Exception('取消失败,库存处理错误');
+        }
+
+        Db::commit();
+        return true;
+    }
+
+    /**
+     * 确定订单
+     */
+    public function receiveOrder($data, $userId)
+    {
+        $nowTime = date('Y-m-d H:i:s', time());
+        $data = $this->model->where(['order_sn' => $data['order_sn'], 'user_id' => $userId])->findOrEmpty()->toArray();
+        if (empty($data)) {
+            throw new Exception('参数错误');
+        }
+        if ($data['status'] != 2) {
+            throw new Exception('订单状态错误');
+        }
+
+        return $this->model->where(['order_sn' => $data['order_sn']])->save(['status' => 4, 'updated_time' => $nowTime]);
+    }
+
+    /**
+     * 计算运费
+     * @param $address 用户地址
+     * @param $data 商品数据
+     * @param $express_template_id 模板ID
+     * 获取运费
+     */
+    public function postFee($address, $data, $express_template_id)
+    {
+        //获取运费模板
+        $expressDelivery = ExpressDeliveryService::make()->getDataByTemplate($express_template_id);
+        //获取运费模板列表
+        $expressDeliveryItems = ExpressShippingMethodService::make()->getListByTemplate($express_template_id);
+
+        $price_method_field = '';
+        switch ($expressDelivery['price_method']) {
+            case 1:
+                $price_method_field = $data['total_price']; //按金额
+                break;
+            case 2:
+                $price_method_field = $data['num'];  //按件数
+                break;
+            case 3:
+                $price_method_field = $data['total_weight']; //按重量
+                break;
+            default:
+                break;
+        }
+
+        if ($expressDelivery['price_method'] == 1) {
+
+            //计算默认运费 【配送区域、免运费金额、达标时运费、未达标时运费;】
+            if ($price_method_field < $expressDelivery['default_free_price']) {
+                $default_postfee = $expressDelivery['default_fastandard_price'];
+            } else {
+                //达标时运费
+                $default_postfee = $expressDelivery['default_price'];
+            }
+
+            if (empty($expressDeliveryItems)) {
+                return $default_postfee;
+            }
+
+            //按指定地区计算邮费
+            foreach ($expressDeliveryItems as $k => $node) {
+                if (in_array($address, explode(',', $node['address_items_ids']))) {
+                    //未达标运费
+                    if ($price_method_field < $node['free_price']) {
+                        return $node['fastandard_price'];
+                    } else {
+                        //达标时运费
+                        return $node['price'];
+                    }
+                } else {
+                    return $default_postfee;
+                }
+            }
+        } else {
+            //按件数 重量计费 【配送区域、首件、达标时运费、续件、未达标时运费】
+            //计算默认运费
+            if ($price_method_field <= $expressDelivery['default_pieces']) {
+                $default_postfee = $expressDelivery['default_price'];
+            } else {
+                //达到续件条件时的运费
+                if ($expressDelivery['add_pieces']) {
+                    //配置过续件费用
+                    //续件数 =  (下单件数 - 首件) /续件数
+                    //总运费 =  首件运费 + (续件数 * 续件费用)
+                    $add_pieces = bcdiv(($price_method_field - $expressDelivery['default_pieces']), $expressDelivery['add_pieces'], 2);
+                    $default_postfee = bcadd($expressDelivery['default_price'], bcmul($add_pieces, $expressDelivery['add_price'], 2), 2);
+                } else {
+                    //未配置过续件,按首件价格
+                    $default_postfee = $expressDelivery['default_price'];
+                }
+            }
+            if (empty($expressDeliveryItems)) {
+                return $default_postfee;
+            }
+            //按指定地区计算邮费
+            foreach ($expressDeliveryItems as $k => $node) {
+                if (in_array($address, explode(',', $node['address_items_ids']))) {
+                    //未达到续件条件时的运费
+                    if ($price_method_field <= $node['pieces']) {
+                        return $node['price'];
+                    } else {
+                        //达到续件条件时的运费
+                        if ($node['add_pieces']) {
+                            //配置过续件费用
+                            //续件数 =  (下单件数 - 首件) /续件数
+                            //总运费 =  首件运费 + (续件数 * 续件费用)
+                            $add_pieces = bcdiv(($price_method_field - $node['pieces']), $node['add_pieces'], 2);
+                            return bcadd($node['price'], bcmul($add_pieces, $node['add_price'], 2), 2);
+                        } else {
+                            //未配置过续件,按首件价格
+                            return $node['price'];
+                        }
+                    }
+                } else {
+                    return $default_postfee;
+                }
+            }
+        }
+    }
+
+    /**
+     * 验证商品库存
+     * @param $data
+     * @return bool
+     */
+    public function checkStock($data)
+    {
+        foreach ($data as $key => $value) {
+            $num = array_sum(array_column($value, 'num'));
+            $goodsSn = isset($value[0]['goods_sn']) ? $value[0]['goods_sn'] : 0;
+            $specId = isset($value[0]['spec_id']) ? $value[0]['spec_id'] : 0;
+            if ($goodsSn && $specId && $num > 0) {
+                $stock = ShopGoodsSpecService::make()->getStock($goodsSn, $specId);
+                if ($num > $stock) {
+                    return false;
+                }
+            } else {
+                return false;
+            }
+
+        }
+
+        return true;
+    }
+
+    /**
+     * 2小时内未付款订单数
+     * @param $uid
+     * @param int $orderType
+     * @param int $status
+     * @return array|int|mixed
+     * @throws \think\db\exception\DbException
+     */
+    public function checkBuyCountByTime($uid, $orderType = 1, $status = 0)
+    {
+        $cacheKey = "caches:orders:unpayCount:{$uid}_{$orderType}_{$status}";
+        $data = RedisCache::get($cacheKey);
+        if ($data) {
+            return $data;
+        }
+
+        $data = $this->model->where(['user_id' => $uid, 'order_type' => $orderType, 'status' => $status])
+            ->whereTime('created_time', '-2 hours')
+            ->count('order_id');
+        if ($data) {
+            RedisCache::set($cacheKey, $data, rand(3, 5));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 根据单号获取订单信息(有缓存)
+     * @param $orderSn 订单号
+     * @param int $uid 所属用户ID
+     * @param string $field 返沪字段
+     * @param bool $cache 是否缓存,默认是
+     * @return array|mixed
+     */
+    public function getInfoBySn($orderSn, $uid=0, $field='', $cache=true)
+    {
+        $cacheKey = "caches:orders:info:sn{$orderSn}_{$uid}".($field? '_'.md5($field):'');
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+        $where = ['order_sn'=> $orderSn,'user_id'=> 0,'status'=>1];
+        if($uid>0){
+            $where['user_id'] = $uid;
+        }else{
+            unset($where['user_id']);
+        }
+
+        $field = $field? $field : 'order_id,order_sn,user_id,payment,total_price,status,pay_type,rebate_score,rebate_money,num,order_type,give_vip,coupon_number,hg_status,hg_enable';
+        $data = $this->model->where($where)->field($field)->findOrEmpty();
+        $data = $data? $data->toArray() : [];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, rand(5,10));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 根据单号获取订单信息(有缓存)
+     * @param $orderSn 订单号
+     * @param int $uid 所属用户ID
+     * @param string $field 返沪字段
+     * @param bool $cache 是否缓存,默认是
+     * @return array|mixed
+     */
+    public function getInfoById($orderId, $uid=0, $field='', $cache=true)
+    {
+        $cacheKey = "caches:orders:info:id{$orderId}_{$uid}".($field? '_'.md5($field):'');
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+        $where = ['order_id'=> $orderId,'user_id'=> 0,'status'=>1];
+        if($uid>0){
+            $where['user_id'] = $uid;
+        }else{
+            unset($where['user_id']);
+        }
+
+        $field = $field? $field : 'order_id,order_sn,user_id,payment,total_price,status,pay_type,rebate_score,rebate_money,num,order_type,give_vip,coupon_number,hg_status,hg_enable';
+        $data = $this->model->where($where)->field($field)->findOrEmpty();
+        $data = $data? $data->toArray() : [];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, rand(5,10));
+        }
+
+        return $data;
+    }
+}

+ 152 - 0
app/common/service/UserBankSignService.php

@@ -0,0 +1,152 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\UserBankSignModel;
+use utils\RedisCache;
+
+/**
+ * 用户等级配置服务 by wes
+ * Class UserBankSignService
+ * @package app\common\service
+ */
+class UserBankSignService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new UserBankSignModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 获取签名绑定的银行卡列表
+     * @param $uid 用户ID
+     * @param int $pageSize
+     * @param string $field
+     * @param string $cache
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getListByUser($uid, $pageSize = 10, $field = '', $cache=true)
+    {
+        $page = request()->post('page', 1);
+        $cacheKey = "caches:temp:ysBankList:{$page}_{$pageSize}_" . md5(json_encode($params));
+        $data = RedisCache::get($cacheKey);
+        if ($data && $cache) {
+            return $data;
+        }
+
+        $field = $field ? $field : 'id,bank_no,bank_name,bank_sub,bank_type,bank_value,status';
+        $data = $this->model->where(['status' => 1])->where(function ($query) use ($params) {
+            $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
+            if ($keyword) {
+                $query->where('bank_name|bank_sub', 'like', "%{$keyword}%");
+            }
+        })
+            ->field($field)
+            ->order('id asc')
+            ->page($page, $pageSize)->select();
+        $data = $data? $data->toArray() : [];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, 3600);
+        }
+
+        return $data;
+    }
+
+    /**
+     * 验证该用户是否已签约该卡
+     * @param $uid
+     * @param $bankCard
+     * @param int $status
+     * @return array|mixed
+     */
+    public function checkHasSign($uid, $bankCard, $status = 4)
+    {
+        $cacheKey = "caches:userBankSign:check:u{$uid}_{$bankCard}_{$status}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $where = ['bank_card'=> $bankCard,'uid'=> $uid,'status'=>$status];
+        $data = $this->model->where($where)->findOrEmpty();
+        $data = $data? $data->toArray():[];
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(5,10));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 按签约单号验证是否已经签约绑定
+     * @param $signOrderId
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function checkHasBySignOrderId($signOrderId)
+    {
+        $cacheKey = "caches:userBankSign:check:so_{$signOrderId}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $where = ['signorder_id'=> $signOrderId];
+        $data = $this->model->where($where)->findOrEmpty();
+        $data = $data? $data->toArray():[];
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(5,10));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 用户绑定银行卡信息
+     * @param $id
+     * @param int $uid
+     * @return array|mixed
+     */
+    public function getCacheInfo($id, $uid=0)
+    {
+        $cacheKey = "caches:userBankSign:info:u{$uid}_{$id}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $where = ['id'=> $id];
+        if($uid){
+            $where['uid'] = $uid;
+        }
+        $data = $this->model->where($where)->findOrEmpty();
+        $data = $data? $data->toArray():[];
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(5,10));
+        }
+
+        return $data;
+    }
+
+
+
+
+}

+ 57 - 0
app/common/service/UserMessageService.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\UserMessageModel;
+use utils\RedisCache;
+
+/**
+ * 用户消息通知服务 by wes
+ * Class UserMessageService
+ * @package app\common\service
+ */
+class UserMessageService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new UserMessageModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 发送保存用户消息
+     * @param array $params
+     * @return false|int|string
+     */
+    public function sendMessage(array $params)
+    {
+        $uid = isset($params['uid'])? $params['uid'] : 0;
+        if($params && $uid>0){
+            $data = [
+                'uid'=> isset($params['uid'])? $params['uid'] : 0,
+                'title'=> isset($params['title'])? $params['title'] : '',
+                'type'=> isset($params['type'])? $params['type'] : '',
+                'banner_desc'=>  isset($params['desc'])? $params['desc'] : '',
+                'create_time'=> sr_getcurtime(time())
+            ];
+            return $this->model->insert($data);
+        }
+
+        return false;
+    }
+}

+ 62 - 0
app/common/service/UserService.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\UserModel;
+use utils\RedisCache;
+
+/**
+ * 用户服务 by wes
+ * Class UserService
+ * @package app\common\service
+ */
+class UserService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new UserModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 用户缓存信息
+     * @param int $uid
+     * @return array|mixed
+     */
+    public function getCacheInfo($uid, $field='', $cache=false)
+    {
+        $cacheKey = "caches:users:info:u{$uid}".($field?'_'.md5($field):'');
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+        $where = ['uid'=> $uid];
+        $field = $field? $field : 'id,user_name,mobile,level,code,pid,money,score,profit_money,level_type,status,is_auth,is_reward,user_type,store_type,has_fd';
+        $data = $this->model->where($where)->field($field)->findOrEmpty();
+        $data = $data? $data->toArray():[];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
+
+
+
+}

+ 37 - 0
app/common/service/WithdrawService.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\WithDrawLogModel;
+use utils\RedisCache;
+
+/**
+ * 提现服务 by wes
+ * Class WithdrawService
+ * @package app\common\service
+ */
+class WithdrawService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new WithDrawLogModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+}

+ 74 - 0
app/common/service/YsBankService.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace app\common\service;
+
+use app\common\model\YsBankListModel;
+use utils\RedisCache;
+
+/**
+ * 银盛银行卡服务 by wes
+ * Class YsBankService
+ * @package app\common\service
+ */
+class YsBankService
+{
+    protected static $instance = null;
+    protected $model = null;
+
+    public function __construct()
+    {
+        $this->model = new YsBankListModel();
+    }
+
+    /**
+     * 静态化入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+    /**
+     * 获取银行卡列表
+     * @param $params 查询参数
+     * @param int $pageSize
+     * @param string $field
+     * @param string $cache
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getList($params, $pageSize = 10, $field = '', $cache=true)
+    {
+        $page = request()->post('page', 1);
+        $cacheKey = "caches:temp:ysBankList:{$page}_{$pageSize}_" . md5(json_encode($params));
+        $data = RedisCache::get($cacheKey);
+        if ($data && $cache) {
+            return $data;
+        }
+
+        $field = $field ? $field : 'id,bank_no,bank_name,bank_sub,bank_type,bank_value,status';
+        $data = $this->model->where(['status' => 1])->where(function ($query) use ($params) {
+                    $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
+                    if ($keyword) {
+                        $query->where('bank_name|bank_sub', 'like', "%{$keyword}%");
+                    }
+                })
+                ->field($field)
+                ->order('id asc')
+                ->page($page, $pageSize)->select();
+        $data = $data? $data->toArray() : [];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, 3600);
+        }
+
+        return $data;
+    }
+
+}