浏览代码

调整制度对应的表,新增时间结算限制

siwenlei 1 年之前
父节点
当前提交
bc7c958149

+ 2 - 0
application/admin/common.php

@@ -195,3 +195,5 @@ if (!function_exists('build_heading')) {
         return $result;
     }
 }
+
+

+ 101 - 59
application/api/controller/Order.php

@@ -3,12 +3,17 @@
 namespace app\api\controller;
 
 
-use app\admin\model\hu\Address;
+
 use app\common\controller\Api;
 use app\common\model\hu\Goods;
 use app\common\model\hu\OrderGoods;
 use app\common\model\hu\UserInvite;
-use app\common\model\hu\WholesaleGoods;
+
+use app\common\model\unishop\OrderExtend;
+use app\common\model\unishop\Product;
+use app\common\model\unishop\Address;
+use app\common\model\unishop\OrderProduct;
+use app\common\model\unishop\WholesaleGoods;
 use think\Db;
 use think\Exception;
 use think\Log;
@@ -22,7 +27,7 @@ class Order extends Api
     public function _initialize()
     {
         parent::_initialize();
-        $this->model = new \app\common\model\hu\Order();
+        $this->model = new \app\common\model\unishop\Order();
     }
 
     /**
@@ -42,21 +47,21 @@ class Order extends Api
 //            $params['goods_info'] = json_decode($params['goods_info'],true);
             $params['goods_info'] = [
                 [
-                    'goods_id'=>1,
+                    'goods_id'=>12,
                     'buy_number'=>1
                 ],
                 [
-                    'goods_id'=>2,
+                    'goods_id'=>13,
                     'buy_number'=>2
                 ],
 
             ];
             $pay_price = 0;
-            $goods_model = new Goods();
+            $product_model = new Product();
             if(!empty($params['goods_info'])){
                 foreach ($params['goods_info'] as $key=>$val){
                     //计算价格
-                   $zj = $goods_model->computePrice($val['goods_id'],$val['buy_number']);
+                   $zj = $product_model->computePrice($val['goods_id'],$val['buy_number']);
                    $pay_price = $pay_price + $zj;
 
                 }
@@ -68,29 +73,45 @@ class Order extends Api
             if($address_id == 0){
                 $address_model = new Address();
                 //使用默认地址
-                $address_id =$address_model->where('user_id',$user_id)->where('status',1)->value('id');
+                $address_id =$address_model->where('user_id',$user_id)->where('is_default',1)->value('id');
                 if(empty($address_id)){
                     $this->error("缺少收货地址信息");
                 }
             }
 
             //插入订单表
-            $data['order_sn'] = $order_sn;
+            $data['out_trade_no'] = $order_sn;
             $data['user_id'] = $user_id;
-            $data['pay_price'] = $pay_price;//实付价格
-            $data['address_id'] = $address_id;//收件地址ID
+            $data['order_price'] = $pay_price;
+            $data['total_price'] = $pay_price;//实付价格
+            $data['ip'] = getip();
+            $data['remark'] = "用户下单";
             $data['createtime'] = time();
-
+            $data['updatetime'] = time();
             $order_id = $this->model->insertGetID($data);
+            if(!$order_id){
+                $this->error('下单失败');
+            }
 
             //插入订单商品表
-            $OrderGoods_model = new OrderGoods();
-            $order_goods_add = $OrderGoods_model->add($params['goods_info'],$user_id,$order_id);
-            if($order_goods_add){
+            $OrderProduct_model = new OrderProduct();
+            $order_goods_add = $OrderProduct_model->add($params['goods_info'],$user_id,$order_id);
+            if(!$order_goods_add){
+                $this->error('下单失败');
+            }
+
+            $coupon_id = isset($params['coupon_id'])?$params['coupon_id']:'0';
+            $delivery_id = isset($params['delivery_id'])?$params['delivery_id']:'0';
+            //插入订单扩展表
+            $orderExtend_model = new OrderExtend();
+            $orderExtend_model_add = $orderExtend_model->add($user_id,$order_id,$coupon_id,$delivery_id,$address_id);
+
+            if($orderExtend_model_add){
                 $this->success('下单成功');
             }else{
-                $this->success('下单失败');
+                $this->error('下单失败');
             }
+
         } catch (Exception $e) {
             $this->error($e->getMessage());
         }
@@ -103,64 +124,85 @@ class Order extends Api
     public function notify(){
 
         try {
+
             //省略验证
             $order_sn = $this->request->param('order_sn');
 
-            $order_info = $this->model->where('order_sn',$order_sn)->find();
+            $order_info = $this->model->where('out_trade_no',$order_sn)->find();
             if(empty($order_info)){
                 $this->error("订单信息有误");
             }
 
             if($order_info['status'] !='1'){
-                exit();
+                $this->error("订单信息有误");
+            }
+
+            if($order_info['have_paid'] != 0){
+                $this->error("订单信息有误");
             }
             //开启事务
             Db::startTrans();
-            $upd = $this->model->where('order_sn',$order_sn)->update(['status'=>2]);
+            $upd = $this->model->where('out_trade_no',$order_sn)->update(['have_paid'=>1]);
             if($upd){
-                //成功 当前下单用户是否有上级  上上级
-                 //上级
-                $UserInvite_model = new UserInvite();
-                $list_one = $UserInvite_model->getUsetInviteOne($order_info['user_id']);
-                //增加抽成
-                $invite_one = Db::name("config")->where('name','invite_one')->value('value');
-                $user_model = new \app\common\model\User();
-                if(!empty($list_one)){
-                    foreach ($list_one as $k=>$val){
-                        //计算佣金
-                        $commission = $this->model->computeCommission($order_info['pay_price'],$invite_one);
-                        //增加佣金和流水日志
-
-                        if(!empty($val['invite_id'])){
-                            $add_one = $user_model->userAddMoney($commission,$val['invite_id'],"直推分佣所得");
-                            if(!$add_one){
-                                //写入失败 写入记录日志
-                                Logs('订单号为:'.$order_info['order_sn'].'增加上级佣金失败','order_err');
-                                Db::rollback();
-                                $this->error("增加上级分佣失败");
+
+                //判断当前时间是否为配置中跳过的星期
+                $not_time = Db::name("config")->where("name","not_time")->value("value");
+                if(!empty($not_time)){
+                    $not_time = explode(',',$not_time);
+                    $day_week = weeks();
+                    if(!in_array($day_week,$not_time)){
+                        //成功 当前下单用户是否有上级  上上级
+                        //上级
+                        $UserInvite_model = new UserInvite();
+                        $list_one = $UserInvite_model->getUsetInviteOne($order_info['user_id']);
+
+                        //增加抽成
+                        $invite_one = Db::name("config")->where('name','invite_one')->value('value');
+                        $user_model = new \app\common\model\User();
+                        if(!empty($list_one)){
+                            foreach ($list_one as $k=>$val){
+                                //计算佣金
+                                $commission = $this->model->computeCommission($order_info['total_price'],$invite_one);
+                                //增加佣金和流水日志
+
+                                if(!empty($val['invite_id'])){
+                                    $add_one = $user_model->userAddMoney($commission,$val['invite_id'],"直推分佣所得");
+                                    if(!$add_one){
+                                        //写入失败 写入记录日志
+                                        Logs('订单号为:'.$order_info['out_trade_no'].'增加上级佣金失败','order_err');
+                                        Db::rollback();
+                                        $this->error("增加上级分佣失败");
+                                    }
+                                }
                             }
                         }
-                    }
-                }
-                //上上级
-                $list_one_top = $UserInvite_model->getUsetInviteOneTop($order_info['user_id']);
-                $invite_two = Db::name("config")->where('name','invite_two')->value('value');
-                if(!empty($list_one_top)){
-                    foreach ($list_one_top as $key=>$value){
-                        //计算佣金
-                        $commission = $this->model->computeCommission($order_info['pay_price'],$invite_two);
-                        //增加佣金和流水日志
-
-                        if(!empty($value['top_id'])){
-                            $add_one_two = $user_model->userAddMoney($commission,$value['top_id'],"二级分佣所得");
-                            if(!$add_one_two){
-                                //写入失败 写入记录日志
-                                Logs('订单号为:'.$order_info['order_sn'].'增加上级佣金失败','order_err');
-                                Db::rollback();
-                                $this->error("增加上上级分佣失败");
+                        //上上级
+                        $list_one_top = $UserInvite_model->getUsetInviteOneTop($order_info['user_id']);
+                        $invite_two = Db::name("config")->where('name','invite_two')->value('value');
+                        if(!empty($list_one_top)){
+                            foreach ($list_one_top as $key=>$value){
+                                //计算佣金
+                                $commission = $this->model->computeCommission($order_info['total_price'],$invite_two);
+                                //增加佣金和流水日志
+
+                                if(!empty($value['top_id'])){
+                                    $add_one_two = $user_model->userAddMoney($commission,$value['top_id'],"二级分佣所得");
+                                    if(!$add_one_two){
+                                        //写入失败 写入记录日志
+                                        Logs('订单号为:'.$order_info['out_trade_no'].'增加上级佣金失败','order_err');
+                                        Db::rollback();
+                                        $this->error("增加上上级分佣失败");
+                                    }
+                                }
+
                             }
                         }
-
+                        //更改订单的结算状态
+                        $giveaway = $this->model->where('out_trade_no',$order_sn)->update(['is_giveaway'=>2,'updatetime'=>time()]);
+                        if(!$giveaway){
+                            Db::rollback();
+                            $this->error("更改订单的结算状态失败");
+                        }
                     }
                 }
 
@@ -169,7 +211,7 @@ class Order extends Api
                 $wholesaleGoods_add = $wholesaleGoods_model->add($order_info['user_id'],$order_info['id']);
                 if(!$wholesaleGoods_add){
                     //写入失败 写入记录日志
-                    Logs('订单号为:'.$order_info['order_sn'].'增加批发商品失败','order_err');
+                    Logs('订单号为:'.$order_info['out_trade_no'].'增加批发商品失败','order_err');
                     Db::rollback();
                     $this->error("增加批发商品失败");
                 }

+ 1 - 1
application/api/controller/Task.php

@@ -3,7 +3,7 @@
 namespace app\api\controller;
 
 use app\admin\command\Api;
-use app\common\model\hu\WholesaleGoods;
+use app\common\model\unishop\WholesaleGoods;
 use think\Db;
 
 /**

+ 115 - 0
application/common.php

@@ -628,3 +628,118 @@ if (!function_exists('Logs')) {
 
 
 }
+
+/**
+ * 获取ip地址
+ * @return mixed|string
+ */
+if (!function_exists('getip')) {
+    function getip() {
+        static $ip = '';
+        $ip = $_SERVER['REMOTE_ADDR'];
+        if(isset($_SERVER['HTTP_CDN_SRC_IP'])) {
+            $ip = $_SERVER['HTTP_CDN_SRC_IP'];
+        } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
+            $ip = $_SERVER['HTTP_CLIENT_IP'];
+        } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
+            foreach ($matches[0] AS $xip) {
+                if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
+                    $ip = $xip;
+                    break;
+                }
+            }
+        }
+        return $ip;
+    }
+}
+
+/**
+ * 获取当前时间的星期数
+ * @return mixed|string
+ */
+if (!function_exists('weeks')) {
+    function weeks($time) {
+        $week_array = array("7", "1", "2", "3", "4", "5", "6");
+        $week = date("w");
+        return $week_array[$week];
+    }
+}
+
+
+/**
+ * 获取指定时间星期方法
+ */
+if (!function_exists('get_week')) {
+
+    function get_week($date)
+    {
+        //强制转换日期格式
+        $date_str = date('Y-m-d', strtotime($date));
+
+        //封装成数组
+        $arr = explode("-", $date_str);
+
+        //参数赋值
+        //年
+        $year = $arr[0];
+
+        //月,输出2位整型,不够2位右对齐
+        $month = sprintf('%02d', $arr[1]);
+
+        //日,输出2位整型,不够2位右对齐
+        $day = sprintf('%02d', $arr[2]);
+
+        //时分秒默认赋值为0;
+        $hour = $minute = $second = 0;
+
+        //转换成时间戳
+        $strap = mktime($hour, $minute, $second, $month, $day, $year);
+
+        //获取数字型星期几
+        $number_wk = date("w", $strap);
+
+        //自定义星期数组
+        $weekArr = array("7", "1", "2", "3", "4", "5", "6");
+
+        //获取数字对应的星期
+        return $weekArr[$number_wk];
+    }
+
+}
+
+/**
+ * 计算指定日期到当前时间有多少个星期几
+ */
+if (!function_exists('getweeknum')) {
+    function getweeknum($targetDate,$week){
+
+        // 指定目标日期
+    //    $targetDate = '2023-8-20';
+
+        // 获取今天和目标日期的日期对象
+        $today = new \DateTime();
+        $target = new \DateTime($targetDate);
+
+        // 计算日期范围
+        $interval = \DateInterval::createFromDateString('1 day'); // 创建一个间隔为1天的时间间隔
+        $period = new \DatePeriod($target, $interval, $today);
+
+        $saturdaysCount = 0;
+
+        // 遍历日期范围
+        foreach ($period as $date) {
+            // 检查是否是星期六
+            if ($date->format('N') == $week) {
+                $saturdaysCount++;
+            }
+        }
+
+        return $saturdaysCount;
+
+
+    }
+}
+
+
+
+

+ 12 - 0
application/common/model/unishop/Address.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace app\common\model\unishop;
+
+use think\Model;
+
+class Address extends Model
+{
+    // 表名
+    protected $name = 'unishop_address';
+    
+}

+ 119 - 0
application/common/model/unishop/Order.php

@@ -0,0 +1,119 @@
+<?php
+
+namespace app\common\model\unishop;
+
+use app\common\model\hu\订单总价格;
+use think\Model;
+use traits\model\SoftDelete;
+
+class Order extends Model
+{
+
+    use SoftDelete;
+
+    
+
+    // 表名
+    protected $name = 'unishop_order';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+        'status_text',
+        'pay_time_text',
+        'send_time_text',
+        'receive_time_text'
+    ];
+    
+
+    
+    public function getStatusList()
+    {
+        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5')];
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPayTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getSendTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['send_time']) ? $data['send_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getReceiveTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['receive_time']) ? $data['receive_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setPayTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setSendTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setReceiveTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+    public function user()
+    {
+        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function address()
+    {
+        return $this->belongsTo('Address', 'address_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function delivery()
+    {
+        return $this->belongsTo('Delivery', 'delivery_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+    /**
+     * 计算佣金
+     * @param $price 订单总价格
+     * @param int $scale 抽佣比
+     * @return string
+     */
+    public function computeCommission($price,int $scale = 0){
+
+        $scale = $scale/100;
+        $commission = bcmul((string)$price,(string)$scale,2);
+
+        return $commission;
+    }
+
+
+}

+ 84 - 0
application/common/model/unishop/OrderExtend.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace app\common\model\unishop;
+
+use think\Db;
+use think\Model;
+use traits\model\SoftDelete;
+
+class OrderExtend extends Model
+{
+
+    use SoftDelete;
+
+    
+
+    // 表名
+    protected $name = 'unishop_order_extend';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+
+    ];
+
+    /**
+     * 订单信息扩展添加
+     * @param $user_id  用户ID
+     * @param $order_id  订单ID
+     * @param $coupon_id 优惠券ID
+     * @param $delivery_id 运费模版ID
+     * @param $address_id  地址ID
+     * @return void
+     */
+    public function add($user_id,$order_id,$coupon_id,$delivery_id,$address_id){
+
+        $data['user_id'] = $user_id;
+        $data['order_id'] = $order_id;
+        $data['coupon_id'] = $coupon_id;
+        $data['delivery_id'] = $delivery_id;
+        $data['address_id'] = $address_id;
+        $data['createtime'] = time();
+        $data['updatetime'] = time();
+
+        if($coupon_id != 0){
+            $coupon_json = Db::name("unishop_coupon")->where('switch',1)->find($coupon_id);
+            if(!empty($coupon_json)){
+                $data['coupon_json'] = json_encode($coupon_json,JSON_UNESCAPED_UNICODE);
+            }
+
+        }
+        if($delivery_id != 0){
+            $delivery_json = Db::name("unishop_delivery")->where('switch',1)->find($delivery_id);
+            if(!empty($delivery_json)){
+                $data['delivery_json'] = json_encode($delivery_json,JSON_UNESCAPED_UNICODE);
+            }
+
+        }
+        if($address_id != 0){
+            $address_json = Db::name("unishop_address")->find($address_id);
+            if(!empty($address_json)){
+                $data['address_json'] = json_encode($address_json,JSON_UNESCAPED_UNICODE);
+            }
+
+        }
+
+        $add = self::insert($data);
+
+        if($add){
+            return true;
+        }else{
+            return false;
+        }
+
+    }
+
+
+}

+ 74 - 0
application/common/model/unishop/OrderProduct.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace app\common\model\unishop;
+
+use app\common\model\unishop\Product;
+use think\Exception;
+use think\Model;
+use traits\model\SoftDelete;
+use think\Db;
+class OrderProduct extends Model
+{
+
+    use SoftDelete;
+
+    
+
+    // 表名
+    protected $name = 'unishop_order_product';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+
+    ];
+
+    /**
+     * 插入订单商品表
+     * @param array $goodArr 商品信息
+     * @param int $user_id   用户ID
+     * @param int $order_id  订单ID
+     * @return bool
+     */
+    public function add(array $goodArr,int $user_id,int $order_id){
+        try {
+            $Goods = new Product();
+            foreach ($goodArr as $key=>$value){
+                $good_info = Db::name("unishop_product")->find($value['goods_id']);
+                if(!empty($good_info)){
+                    $data['user_id'] = $user_id;
+                    $data['order_id'] = $order_id;
+                    $data['product_id'] = $value['goods_id'];
+                    $data['title'] = $good_info['title'];
+                    $data['image'] = $good_info['image'];
+                    $data['number'] = $value['buy_number'];
+                    $data['price'] = $good_info['sales_price'];
+                    $data['product_json'] = json_encode($good_info,JSON_UNESCAPED_UNICODE);
+                    $data['amounts'] = $Goods->computePrice($value['goods_id'],$value['buy_number']);
+                    $data['createtime'] = time();
+                    $data['updatetime'] = time();
+                    $data['spec'] = 0;
+                    $data['images'] = $good_info['images'];
+
+                    self::insert($data);
+
+                }
+            }
+
+            return  true;
+        }catch (Exception $e) {
+
+            return false;
+        }
+
+    }
+    
+
+}

+ 45 - 0
application/common/model/unishop/Product.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace app\common\model\unishop;
+
+use think\Model;
+use traits\model\SoftDelete;
+
+class Product extends Model
+{
+
+    use SoftDelete;
+
+
+
+    // 表名
+    protected $name = 'unishop_product';
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+
+    ];
+
+    /**
+     * 计算订单商品总价
+     * @param $goods_id  商品ID
+     * @param $num  数量
+     * @return int|mixed|string
+     */
+    public function computePrice($goods_id,$num){
+
+        $price = self::where('id',$goods_id)->value('sales_price');
+
+        return bcmul((string)$price,(string)$num,2);
+
+    }
+
+}

+ 139 - 0
application/common/model/unishop/WholesaleGoods.php

@@ -0,0 +1,139 @@
+<?php
+
+namespace app\common\model\unishop;
+
+use think\Exception;
+use think\Model;
+use traits\model\SoftDelete;
+use think\Db;
+class WholesaleGoods extends Model
+{
+
+    use SoftDelete;
+
+    
+
+    // 表名
+    protected $name = 'unishop_wholesale_goods';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+
+    ];
+
+    /**
+     * @param int $user_id   用户ID
+     * @param int $order_id  订单ID
+     * @return bool
+     */
+    public function add(int $user_id, int $order_id){
+        try {
+            //查询生成数目
+            $shop_num = Db::name('config')->where("name","shop_nums")->value('value');
+            $shop_num = isset($shop_num)?$shop_num:2;
+           //查询当前订单的商品
+            $list = Db::name("unishop_order_product")->where('order_id',$order_id)->where('user_id',$user_id)->select();
+
+            //增加批发商品表数据
+
+            foreach ($list as $key=>$value){
+                $goods_ratio = Db::name("unishop_product")->where("id",$value['product_id'])->value("ratio");
+                $goods_ratio = $goods_ratio/100;
+                $goods_info = Db::name("unishop_product")->where("id",$value['product_id'])->find("ratio");
+                $price = bcmul((string)$goods_ratio,(string)$value['price'],2);
+                $data['user_id'] = $user_id;
+                $data['goods_id'] = $value['product_id'];
+                $data['title'] = $value['title'];
+                $data['image'] = $value['image'];
+                $data['images'] = $value['images'];
+                $data['desc'] = '用户下单支付生成批发商品';
+                $data['market_price'] = $goods_info['market_price']??0;
+                $data['sales_price'] = $price??0;
+                $data['sales'] = $goods_info['sales']??0;
+                $data['stock'] = $value['number']*$shop_num;
+                $data['weigh'] = $goods_info['weigh']??0;
+                $data['switch'] = $goods_info['switch']??1;
+                $data['createtime'] = time();
+
+               self::insert($data);
+
+            }
+            return true;
+        }catch (Exception $e) {
+
+            return false;
+        }
+
+    }
+
+    /**
+     * 到时间自动售出
+     * @param  $shop_days 应到期天数
+     * @return void
+     */
+    public function sale($shop_days){
+
+        $not_time = Db::name("config")->where("name","not_time")->value("value");
+        if(!empty($not_time)){
+            $not_time_arr = explode(',',$not_time);
+        }
+        $list = self::where('switch',1)->order('createtime asc')->select();
+
+
+
+       $times = time();
+
+       //天数转时间戳
+        $shop_days_time = $shop_days*86400;
+
+        if(!empty($list)){
+            foreach ($list as $key=>$value){
+                 $num = 0;
+                 foreach ($not_time_arr as $k=>$val){
+                     $num = $num + getweeknum(date('Y-m-d',$value['createtime']),$val);
+                 }
+                 //根据天数增加时间戳
+                 $days = $num*86400;
+                 //结束时间 = 创建时间戳+过期天数+休息日
+                $end_time = $value['createtime']+$shop_days_time+$days;
+                if($end_time<$times){
+                    //到期
+                    $upd = self::where('id',$value['id'])->update(['switch'=>0]);
+                    if($upd){
+                        //增加积分/金额
+                       $update_money = bcmul((string)$value['stock'],(string)$value['sales_price'],2);
+                       $money = Db::name("user")->where('id',$value['user_id'])->value('money');
+                       $sum = bcadd((string)$update_money,(string)$money,2);
+                       $money_upd = Db::name("user")->where('id',$value['user_id'])->update(['money'=>$sum]);
+                       if(!$money_upd){
+                           Logs('批发商品ID为:'.$value['id'].'增加积分失败','Task');
+                       }else{
+                           //写入流水
+                           $is_log = setUserMoneyLog($value['user_id'],$money,$update_money,$sum,1,"批发商品售出");
+                           if($is_log  == 2){
+                               Logs('批发商品ID为:'.$value['id'].'增加积分流水记录失败','Task');
+                           }
+                       }
+                    }else{
+                        //写入失败 写入记录日志
+                        Logs('批发商品ID为:'.$value['id'].'自动售出失败','Task');
+                    }
+
+
+                }
+            }
+        }
+
+
+    }
+    
+
+}

+ 1 - 1
application/extra/site.php

@@ -47,7 +47,7 @@ return array (
   'invite_one' => '3',
   'invite_two' => '1',
   'shop_nums' => '2',
-  'Not time' => 
+  'not_time' => 
   array (
     0 => '7',
   ),

+ 3 - 0
public/log/order_err.txt

@@ -1 +1,4 @@
 2023-08-30 17:23:24-------订单号为:D202308301527513641增加上级佣金失败
+2023-08-31 16:41:19-------订单号为:D202308311536543749增加批发商品失败
+2023-08-31 16:48:21-------订单号为:D202308311645558392增加批发商品失败
+2023-08-31 17:00:37-------订单号为:D202308311645558392增加批发商品失败