初始化代码
This commit is contained in:
550
app/shop/model/DistributionCash.php
Normal file
550
app/shop/model/DistributionCash.php
Normal file
@@ -0,0 +1,550 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\Claim;
|
||||
use app\farm\model\LandList;
|
||||
use app\farm\model\ShopGoods;
|
||||
use app\farm\model\User;
|
||||
use app\farm\server\Land;
|
||||
use think\facade\Db;
|
||||
|
||||
class DistributionCash extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
protected $name = 'lbfarm_v2_distribution_cash_list';
|
||||
|
||||
protected $append = [
|
||||
|
||||
'order_goods'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:商品详情
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 17:44
|
||||
*/
|
||||
public function getOrderGoodsAttr($value,$data){
|
||||
|
||||
if(!empty($data['type'])&&!empty($data['id'])){
|
||||
|
||||
$goods_model = new DistributionGoods();
|
||||
|
||||
if($data['type']==1){
|
||||
|
||||
$list = $goods_model->getShopGoods($data['id']);
|
||||
|
||||
}elseif($data['type']==2){
|
||||
|
||||
$list = $goods_model->getLandGoods($data['id']);
|
||||
|
||||
}else{
|
||||
|
||||
$list = $goods_model->getCliamGoods($data['id']);
|
||||
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-21 17:02
|
||||
*/
|
||||
public function returnType($type){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
|
||||
$text = '商城产品';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
$text = '土地产品';
|
||||
|
||||
break;
|
||||
case 3:
|
||||
|
||||
$text = '认养产品';
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
$text = '商城产品';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page=10){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $order
|
||||
* @param $type
|
||||
* @param int $status
|
||||
* @功能说明:添加商城分销记录
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 13:51
|
||||
*/
|
||||
public function addUserCashShop($fx_id,$top_id,$order,$type,$status=1){
|
||||
|
||||
|
||||
if(!empty($order['order_goods'])){
|
||||
|
||||
$goods_model = new ShopGoods();
|
||||
|
||||
$cash_goods_model = new DistributionGoods();
|
||||
|
||||
$is_fx = $total_cash = 0;
|
||||
|
||||
foreach ($order['order_goods'] as &$v){
|
||||
|
||||
$goods_info = $goods_model->dataInfo(['id'=>$v['goods_id']]);
|
||||
|
||||
if(!empty($goods_info['is_fx'])){
|
||||
|
||||
$v['fx_balance'] = $type==1?$goods_info['one_fx']:$goods_info['two_fx'];
|
||||
|
||||
$v['is_fx'] = $goods_info['is_fx'];
|
||||
|
||||
$v['fx_cash']= $v['pay_price']*$v['fx_balance']/100;
|
||||
|
||||
$total_cash += $v['fx_cash'];
|
||||
|
||||
$is_fx = 1;
|
||||
|
||||
}
|
||||
}
|
||||
//说明有分销商品
|
||||
if($is_fx==1){
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $top_id,
|
||||
|
||||
'source_id' => $order['user_id'],
|
||||
|
||||
'order_code'=> $order['order_code'],
|
||||
|
||||
'transaction_id'=> $order['transaction_id'],
|
||||
|
||||
'order_id' => $order['id'],
|
||||
|
||||
'type' => 1,
|
||||
|
||||
'status' => $status,
|
||||
|
||||
'fx_type' => $type,
|
||||
|
||||
'cash' => round($total_cash,2),
|
||||
|
||||
'reseller_id'=> $fx_id,
|
||||
];
|
||||
|
||||
$this->dataAdd($insert);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
foreach ($order['order_goods'] as $v){
|
||||
|
||||
if($v['is_fx']==1){
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'cash_id' => $id,
|
||||
|
||||
'order_goods_id' => $v['id'],
|
||||
|
||||
'balance' => $v['fx_balance'],
|
||||
|
||||
'cash' => $v['fx_cash'] ,
|
||||
|
||||
'single_cash'=> round($v['fx_cash']/$v['goods_num'],2),
|
||||
|
||||
'num' => $v['goods_num'],
|
||||
];
|
||||
|
||||
$cash_goods_model->dataAdd($insert);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $order
|
||||
* @param $type
|
||||
* @param int $status
|
||||
* @功能说明:添加土地订单分销
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 13:53
|
||||
*/
|
||||
public function addUserCashLand($fx_id,$top_id,$order,$type,$status=1){
|
||||
|
||||
$land_model = new LandList();
|
||||
|
||||
$land = $land_model->dataInfo(['id'=>$order['land_id']]);
|
||||
|
||||
if(!empty($land['is_fx'])){
|
||||
|
||||
$fx_balance = $type==1?$land['one_fx']:$land['two_fx'];
|
||||
|
||||
$total_cash = $order['pay_price']*$fx_balance/100;
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $top_id,
|
||||
|
||||
'source_id' => $order['user_id'],
|
||||
|
||||
'order_code'=> $order['order_code'],
|
||||
|
||||
'transaction_id'=> $order['transaction_id'],
|
||||
|
||||
'order_id' => $order['id'],
|
||||
|
||||
'type' => 2,
|
||||
|
||||
'status' => $status,
|
||||
|
||||
'fx_type' => $type,
|
||||
|
||||
'reseller_id'=> $fx_id,
|
||||
|
||||
'cash' => round($total_cash,2),
|
||||
];
|
||||
|
||||
$this->dataAdd($insert);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'cash_id' => $id,
|
||||
|
||||
'order_goods_id' => $order['id'],
|
||||
|
||||
'balance' => $fx_balance,
|
||||
|
||||
'cash' => $total_cash ,
|
||||
|
||||
'single_cash'=> $total_cash,
|
||||
|
||||
'num' => 1,
|
||||
];
|
||||
|
||||
$cash_goods_model = new DistributionGoods();
|
||||
|
||||
$cash_goods_model->dataAdd($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $order
|
||||
* @param $type
|
||||
* @param int $status
|
||||
* @功能说明:添加认养订单分销
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 13:53
|
||||
*/
|
||||
public function addUserCashClaim($fx_id,$top_id,$order,$type,$status=1){
|
||||
|
||||
$land_model = new Claim();
|
||||
|
||||
$land = $land_model->dataInfo(['id'=>$order['claim_id']]);
|
||||
|
||||
if(!empty($land['is_fx'])){
|
||||
|
||||
$fx_balance = $type==1?$land['one_fx']:$land['two_fx'];
|
||||
|
||||
$total_cash = $order['pay_price']*$fx_balance/100;
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $top_id,
|
||||
|
||||
'source_id' => $order['user_id'],
|
||||
|
||||
'order_code'=> $order['order_code'],
|
||||
|
||||
'transaction_id'=> $order['transaction_id'],
|
||||
|
||||
'order_id' => $order['id'],
|
||||
|
||||
'type' => 3,
|
||||
|
||||
'status' => $status,
|
||||
|
||||
'fx_type' => $type,
|
||||
|
||||
'reseller_id' => $fx_id,
|
||||
|
||||
'cash' => round($total_cash,2),
|
||||
];
|
||||
|
||||
$this->dataAdd($insert);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'cash_id' => $id,
|
||||
|
||||
'order_goods_id' => $order['id'],
|
||||
|
||||
'balance' => $fx_balance,
|
||||
|
||||
'cash' => $total_cash ,
|
||||
|
||||
'single_cash'=> round($total_cash/$order['num']),
|
||||
|
||||
'num' => $order['num'],
|
||||
];
|
||||
|
||||
$cash_goods_model = new DistributionGoods();
|
||||
|
||||
$cash_goods_model->dataAdd($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 15:47
|
||||
* @功能说明:增加佣金信息
|
||||
*/
|
||||
public function addUserCash($order,$type=1){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$top_id = $user_model->where(['id'=>$order['user_id'],'is_fx'=>1])->value('pid');
|
||||
//没有上级不往下执行
|
||||
if(empty($top_id)){
|
||||
|
||||
return true;
|
||||
}
|
||||
//二级分销
|
||||
if($type==2){
|
||||
|
||||
$top_id = $user_model->where(['id'=>$top_id,'is_fx'=>1])->value('pid');
|
||||
|
||||
if(empty($top_id)){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$fx_model = new DistributionList();
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $top_id,
|
||||
|
||||
'status' => 2
|
||||
];
|
||||
//查询分销id
|
||||
$fx_id = $fx_model->where($dis)->value('id');
|
||||
|
||||
if(empty($fx_id)){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($type==1){
|
||||
//商城一级分销
|
||||
$this->addUserCashShop($fx_id,$top_id,$order,1);
|
||||
//商城二级分销
|
||||
$this->addUserCashShop($fx_id,$top_id,$order,2);
|
||||
|
||||
}elseif ($type==2){
|
||||
//土地一级分销
|
||||
$this->addUserCashLand($fx_id,$top_id,$order,1);
|
||||
//土地二级分销
|
||||
$this->addUserCashLand($fx_id,$top_id,$order,2);
|
||||
|
||||
}else{
|
||||
//土地一级分销
|
||||
$this->addUserCashClaim($fx_id,$top_id,$order,1);
|
||||
//土地二级分销
|
||||
$this->addUserCashClaim($fx_id,$top_id,$order,2);
|
||||
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-28 17:18
|
||||
* @功能说明:佣金到账
|
||||
*/
|
||||
public function cashArrival($order,$type=1){
|
||||
|
||||
$dis = [
|
||||
|
||||
'order_id' => $order['id'],
|
||||
|
||||
'type' => $type,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$list = $this->dataInfo($dis);
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
$res = $this->dataUpdate($dis,['status'=>2]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$cash = $list['cash'];
|
||||
|
||||
$res = $user_model->where(['id'=>$order['user_id']])->update(['fx_cash'=>Db::Raw("fx_cash+$cash")]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-29 11:49
|
||||
* @功能说明:分销佣金列表
|
||||
*/
|
||||
public function adminCashList($dis,$where,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_distribution_list b','a.reseller_id = b.id','left')
|
||||
->join('lbfarm_user_list c','a.user_id = c.id','left')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->field('a.*,c.nickName,b.user_name')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
154
app/shop/model/DistributionGoods.php
Normal file
154
app/shop/model/DistributionGoods.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class DistributionGoods extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
protected $name = 'lbfarm_v2_distribution_goods_list';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 17:46
|
||||
* @功能说明:获取商城商品
|
||||
*/
|
||||
public function getShopGoods($cash_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.cash_id' => $cash_id
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_shop_order_goods b','a.order_goods_id = b.id')
|
||||
->where($dis)
|
||||
->field('b.goods_name,b.goods_cover,b.spe_name,b.pay_price,a.*,b.singe_pay_price')
|
||||
->group('a.id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 17:54
|
||||
* @功能说明:获取土地商品
|
||||
*/
|
||||
public function getLandGoods($cash_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.cash_id' => $cash_id
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_land_order b','a.order_goods_id = b.id')
|
||||
->where($dis)
|
||||
->field('b.goods_name,b.goods_cover,b.spe_name,b.pay_price,a.*,b.pay_price as singe_pay_price ')
|
||||
->group('a.id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-27 17:54
|
||||
* @功能说明:获取认养商品
|
||||
*/
|
||||
public function getCliamGoods($cash_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.cash_id' => $cash_id
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim_order b','a.order_goods_id = b.id')
|
||||
->where($dis)
|
||||
->field('b.goods_name,b.goods_cover,b.spe_name,b.pay_price,a.*,b.pay_price as singe_pay_price')
|
||||
->group('a.id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
244
app/shop/model/DistributionList.php
Normal file
244
app/shop/model/DistributionList.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\FinanceWater;
|
||||
use app\farm\model\User;
|
||||
use think\facade\Db;
|
||||
|
||||
class DistributionList extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
protected $name = 'lbfarm_v2_distribution_list';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @功能说明:我的状态
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-28 10:00
|
||||
*/
|
||||
public function myTeam($user_id,$type=1){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$dis[] = ['is_fx','=',1];
|
||||
|
||||
if($type==1){
|
||||
|
||||
$dis[] = ['pid','=',$user_id];
|
||||
|
||||
}else{
|
||||
|
||||
$top_id = $user_model->where(['pid'=>$user_id,'is_fx'=>1])->column('id');
|
||||
|
||||
$dis[] = ['pid','in',$top_id];
|
||||
|
||||
}
|
||||
|
||||
$data = $user_model->where($dis)->field('id,nickName,avatarUrl,fx_bind_time')->order('fx_bind_time desc')->paginate(10)->toArray();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
$water_model = new FinanceWater();
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['fx_bind_time'] = date('Y-m-d H:i:s',$v['fx_bind_time']);
|
||||
|
||||
$dis = [
|
||||
|
||||
'is_fx' => 1,
|
||||
|
||||
'pid' => $v['id']
|
||||
];
|
||||
//推广人数
|
||||
$v['team_count'] = $user_model->where($dis)->count();
|
||||
|
||||
$order_data = $water_model->resellerCashData($v['id']);
|
||||
|
||||
$v = array_merge($v,$order_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @param int $type
|
||||
* @功能说明:团队人数
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-28 17:58
|
||||
*/
|
||||
public function teamCount($user_id,$type=1){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$dis[] = ['is_fx','=',1];
|
||||
|
||||
if($type==1){
|
||||
|
||||
$dis[] = ['pid','=',$user_id];
|
||||
|
||||
}else{
|
||||
|
||||
$top_id = $user_model->where(['pid'=>$user_id,'is_fx'=>1])->column('id');
|
||||
|
||||
$dis[] = ['pid','in',$top_id];
|
||||
|
||||
}
|
||||
|
||||
$data = $user_model->where($dis)->count();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-30 11:26
|
||||
* @功能说明:后台列表
|
||||
*/
|
||||
public function adminDataList($dis,$page=10,$where=[]){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_user_list b','a.user_id = b.id','left')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->field('a.*,b.nickName,b.avatarUrl')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:用户收益列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-29 14:50
|
||||
*/
|
||||
public function userProfitList($dis,$page=10,$where=[]){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$data = $user_model->alias('a')
|
||||
->join('lbfarm_v2_distribution_list b','a.id = b.user_id','left')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->field('b.*,a.nickName,a.avatarUrl,a.fx_cash')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:用户收益列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-29 14:50
|
||||
*/
|
||||
public function userProfitSelect($dis,$where=[]){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$data = $user_model->alias('a')
|
||||
->join('lbfarm_v2_distribution_list b','a.id = b.user_id','left')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->field('b.*,a.nickName,a.avatarUrl,a.fx_cash')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
103
app/shop/model/FreightConfig.php
Normal file
103
app/shop/model/FreightConfig.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class FreightConfig extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_freight_template_config';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'province'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-11 17:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getProvinceAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$config_model = new FreightProvince();
|
||||
|
||||
$list = $config_model->where(['config_id'=>$data['id']])->column('province');
|
||||
|
||||
return array_values($list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
77
app/shop/model/FreightProvince.php
Normal file
77
app/shop/model/FreightProvince.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class FreightProvince extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_freight_template_province';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
219
app/shop/model/FreightTemplate.php
Normal file
219
app/shop/model/FreightTemplate.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class FreightTemplate extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_freight_template';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'config'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-11 17:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getConfigAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$config_model = new FreightConfig();
|
||||
|
||||
$list = $config_model->where(['template_id'=>$data['id']])->select()->toArray();
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @功能说明:添加模版
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-11 16:32
|
||||
*/
|
||||
public function tmplAdd($data){
|
||||
|
||||
if(isset($data['config'])){
|
||||
|
||||
$config = $data['config'];
|
||||
|
||||
|
||||
unset($data['config']);
|
||||
|
||||
}
|
||||
|
||||
$res = $this->dataAdd($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($config)){
|
||||
|
||||
$this->updateSome($config,$id,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-11 16:37
|
||||
*/
|
||||
public function tmplUpdate($dis,$data){
|
||||
|
||||
if(isset($data['config'])){
|
||||
|
||||
$config = $data['config'];
|
||||
|
||||
unset($data['config']);
|
||||
|
||||
}
|
||||
|
||||
$res = $this->dataUpdate($dis,$data);
|
||||
|
||||
if(isset($config)){
|
||||
|
||||
$this->updateSome($config,$dis['id'],$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $id
|
||||
* @param $uniacid
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-11 16:11
|
||||
*/
|
||||
public function updateSome($data,$id,$uniacid){
|
||||
|
||||
$config_model = new FreightConfig();
|
||||
|
||||
$province_model = new FreightProvince();
|
||||
|
||||
$config_model->where(['template_id'=>$id])->delete();
|
||||
|
||||
$province_model->where(['template_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $key=>$value){
|
||||
|
||||
$value['uniacid'] = $uniacid;
|
||||
|
||||
$value['template_id'] = $id;
|
||||
|
||||
$province = $value['province'];
|
||||
|
||||
unset($value['province']);
|
||||
|
||||
$config_model->dataAdd($value);
|
||||
|
||||
$config_id = $config_model->getLastInsID();
|
||||
|
||||
foreach ($province as $ks=>$vs){
|
||||
|
||||
$insert[$ks] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'config_id'=> $config_id,
|
||||
|
||||
'province' => $vs,
|
||||
|
||||
'template_id' => $id
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
$province_model->saveAll($insert);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
187
app/shop/model/GoodsSpePrice.php
Normal file
187
app/shop/model/GoodsSpePrice.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class GoodsSpePrice extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_shop_spe_price';
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* 查询器
|
||||
*/
|
||||
protected $append = [
|
||||
'spe_array_text',
|
||||
'spe_name_text'
|
||||
];
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* get spename
|
||||
*/
|
||||
public function getSpeNameTextAttr($value,$data){
|
||||
$pec_id = explode('-',$data['spe_id_1']);
|
||||
$spe_names = Db::name('lbfarm_v2_shop_spe')->where(['status'=>1])->where('id','IN',$pec_id)->select()->toArray();
|
||||
if(!empty($spe_names)){
|
||||
foreach ($spe_names as $value){
|
||||
$spe_name[] = $value['title'];
|
||||
}
|
||||
return implode('-',$spe_name);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* get spearray
|
||||
*/
|
||||
public function getSpeArrayTextAttr($value,$data){
|
||||
return explode('-',$data['spe_id_1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @return mixed
|
||||
* 获取商品多规格价格库存
|
||||
*/
|
||||
public function goodsSpePrice($dis){
|
||||
$data = $this->where($dis)->select()->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 添加商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpePriceAdd($data){
|
||||
$data['create_time'] = time();
|
||||
$data['status'] = 1;
|
||||
$res = $this->insert($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 添加商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpePriceSaveAll($data){
|
||||
$res = $this->saveAll($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 编辑啊商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpePriceUpdate($dis,$data){
|
||||
$data['update_time'] = time();
|
||||
$res = $this->where($dis)->update($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* 根据条件获取id
|
||||
*/
|
||||
|
||||
public function goodsSpePriceId($dis){
|
||||
$data = $this->where($dis)->column('id');
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @return mixed
|
||||
* 获取商品多规格价格库存
|
||||
*/
|
||||
public function singeSpePrice($dis){
|
||||
$data = $this->where($dis)->find();
|
||||
return !empty($data)?$data->toArray():$data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-08-25 16:13
|
||||
* @功能说明:获取售罄的商品id
|
||||
*/
|
||||
public function getSellOut($uniacid,$type=0){
|
||||
|
||||
$dis[] = ['uniacid','=', $uniacid];
|
||||
|
||||
$dis[] = ['status','=', 1];
|
||||
|
||||
$all_goods = $this->where($dis)->column('goods_id');
|
||||
|
||||
$dis[] = ['stock','>',0];
|
||||
|
||||
$diff_goods = $this->where($dis)->column('goods_id');
|
||||
|
||||
if($type==1){
|
||||
|
||||
return $diff_goods;
|
||||
}
|
||||
|
||||
$data = array_diff($all_goods,$diff_goods);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-08-26 09:53
|
||||
* @功能说明:获取商品库存
|
||||
*/
|
||||
public function getGoodsStock($goods_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'goods_id' => $goods_id,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$stock = $this->where($dis)->sum('stock');
|
||||
|
||||
return is_numeric($stock)?$stock:0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-01-19 18:15
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
195
app/shop/model/IntegralGoods.php
Normal file
195
app/shop/model/IntegralGoods.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class IntegralGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_integral_shop_goods';
|
||||
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'spe_name'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:54
|
||||
* @功能说明:规格名字
|
||||
*/
|
||||
public function getSpeNameAttr($value,$data){
|
||||
|
||||
if(!empty($data['spe_id'])){
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$info = $spe_model->dataInfo(['id'=>$data['spe_id']]);
|
||||
|
||||
if(!empty($info)){
|
||||
|
||||
return $info['spe_name_text'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 13:34
|
||||
* @功能说明:积分列表可以通过商品名字查询
|
||||
*/
|
||||
public function dataGoodsList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('longbing_card_v2_shop_goods b','a.goods_id = b.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.name as goods_name')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 13:54
|
||||
* @功能说明:初始化活动时间
|
||||
*/
|
||||
public function initAtv(){
|
||||
|
||||
$this->where('start_time','>',time())->update(['atv_status'=>1]);
|
||||
|
||||
$this->where('start_time','<',time())->update(['atv_status'=>2]);
|
||||
|
||||
$this->where('end_time','>',time())->update(['atv_status'=>3]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 17:58
|
||||
* @功能说明:修改
|
||||
*/
|
||||
public function updateAtvStock($integral_id,$goods_id,$spe_id,$num,$type=1){
|
||||
|
||||
$dis = [
|
||||
|
||||
'atv_id' => $integral_id,
|
||||
|
||||
'goods_id'=> $goods_id,
|
||||
|
||||
'spe_id' => $spe_id
|
||||
|
||||
];
|
||||
|
||||
$integral_goods_model = new IntegralGoods();
|
||||
|
||||
$find = $integral_goods_model->dataInfo($dis);
|
||||
|
||||
if($type==1){
|
||||
|
||||
if(empty($find)){
|
||||
|
||||
return ['code'=>500,'msg'=>'积分活动已下架'];
|
||||
|
||||
}
|
||||
|
||||
if($find['have_stock']+$num>$find['stock']){
|
||||
|
||||
return ['code'=>500,'msg'=>'可兑换数量不足'];
|
||||
|
||||
}
|
||||
|
||||
$integral_goods_model->where($dis)->update(['have_stock'=> Db::Raw("have_stock+$num")]);
|
||||
|
||||
}else{
|
||||
|
||||
if(!empty($find)){
|
||||
|
||||
$integral_goods_model->where($dis)->update(['have_stock'=> Db::Raw("have_stock-$num")]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
656
app/shop/model/IntegralList.php
Normal file
656
app/shop/model/IntegralList.php
Normal file
@@ -0,0 +1,656 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\ShopGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class IntegralList extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_integral_shop';
|
||||
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'show_price',
|
||||
|
||||
'all_stock',
|
||||
|
||||
'all_have_stock',
|
||||
|
||||
'goods_info',
|
||||
|
||||
'store_info'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取门店信息
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-13 18:38
|
||||
*/
|
||||
public function getStoreInfoAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$store_model = new IntegralStore();
|
||||
$dis = [
|
||||
|
||||
'a.integral_id' => $data['id'],
|
||||
|
||||
'b.status' => 2,
|
||||
|
||||
'b.type' => 2
|
||||
];
|
||||
|
||||
$list = $store_model->alias('a')
|
||||
->join('lbfarm_farmer b','a.store_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.title,b.is_admin,b.cover')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return array_values($list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:52
|
||||
* @功能说明:参与活动的商品规格信息
|
||||
*/
|
||||
public function getGoodsInfoAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$i_model = new IntegralGoods();
|
||||
|
||||
$list = $i_model->alias('a')
|
||||
->join('lbfarm_v2_shop_spe_price b','a.spe_id = b.id')
|
||||
->where(['a.atv_id' => $data['id']])
|
||||
->field(['b.stock as goods_stock','b.price as goods_price','a.*'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:46
|
||||
* @功能说明:获取第一个规格的价格
|
||||
*/
|
||||
public function getShowPriceAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$i_model = new IntegralGoods();
|
||||
|
||||
$info = $i_model->dataInfo(['atv_id'=>$data['id']]);
|
||||
|
||||
$text = '';
|
||||
|
||||
if(!empty($info['integral'])){
|
||||
|
||||
$text .= $info['integral'].'积分';
|
||||
}
|
||||
|
||||
if(!empty($info['price'])){
|
||||
|
||||
$text .= '+'.$info['price'].'元';
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:50
|
||||
* @功能说明:总的库存
|
||||
*/
|
||||
public function getAllStockAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$i_model = new IntegralGoods();
|
||||
|
||||
$num = $i_model->where(['atv_id'=>$data['id']])->sum('stock');
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:50
|
||||
* @功能说明:总的库存
|
||||
*/
|
||||
public function getAllHaveStockAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$i_model = new IntegralGoods();
|
||||
|
||||
$num = $i_model->where(['atv_id'=>$data['id']])->sum('have_stock');
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$goods_info = $data['goods_info'];
|
||||
|
||||
unset($data['goods_info']);
|
||||
|
||||
// $store_info = $data['store_info'];
|
||||
//
|
||||
// unset($data['store_info']);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$res = $this->updateSome($id,$data,$goods_info);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:21
|
||||
* @功能说明:
|
||||
*/
|
||||
public function updateSome($id,$data,$goods_info){
|
||||
|
||||
$i_model = new IntegralGoods();
|
||||
|
||||
$atv = $this->dataInfo(['id'=>$id]);
|
||||
|
||||
$arr = [];
|
||||
|
||||
if(!empty($goods_info)){
|
||||
|
||||
foreach ($goods_info as &$value){
|
||||
|
||||
$i_dis = [
|
||||
|
||||
'atv_id' => $id,
|
||||
|
||||
'goods_id'=> $data['goods_id'],
|
||||
|
||||
'spe_id' => $value['spe_id'],
|
||||
];
|
||||
|
||||
$have_stock = $i_model->where($i_dis)->value('have_stock');
|
||||
|
||||
$i_model->where($i_dis)->delete();
|
||||
|
||||
$where = [];
|
||||
|
||||
$where[] = ['a.goods_id','=',$data['goods_id']];
|
||||
|
||||
$where[] = ['b.spe_id','=',$value['spe_id']];
|
||||
|
||||
$where[] = ['a.status','>',-1];
|
||||
|
||||
$where[] = ['a.id','<>',$id];
|
||||
|
||||
$info = $i_model->alias('b')
|
||||
->join('lbfarm_v2_integral_shop a','a.id = b.atv_id')
|
||||
->where($where)
|
||||
->field('a.*,b.*')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if(!empty($info)){
|
||||
|
||||
foreach ($info as $vs){
|
||||
|
||||
$res = is_time_cross($vs['start_time'],$vs['end_time'],$atv['start_time'],$atv['end_time']);
|
||||
|
||||
if($res==false){
|
||||
|
||||
return ['code'=>500,'msg'=>'规格'.$vs['spe_name'].'该时间段已有积分活动,请先删除,再添加'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'goods_id'=> $data['goods_id'],
|
||||
|
||||
'spe_id' => $value['spe_id'],
|
||||
|
||||
'stock' => $value['stock'],
|
||||
|
||||
'price' => $value['price'],
|
||||
|
||||
'integral'=> $value['integral'],
|
||||
|
||||
'have_stock'=> !empty($have_stock)?$have_stock:0,
|
||||
|
||||
'atv_id' => $id,
|
||||
];
|
||||
|
||||
$i_model->dataAdd($insert);
|
||||
|
||||
$arr[] = $i_model->getLastInsID();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$i_model->where('id','not in',$arr)->where('atv_id','=',$id)->delete();
|
||||
|
||||
// $store_model = new IntegralStore();
|
||||
//
|
||||
// $store_model->where(['integral_id'=>$id])->delete();
|
||||
//
|
||||
// foreach ($store_info as $k=>$v){
|
||||
//
|
||||
// $store_insert[$k] = [
|
||||
//
|
||||
// 'uniacid' => $data['uniacid'],
|
||||
//
|
||||
// 'integral_id' => $id,
|
||||
//
|
||||
// 'store_id' => $v
|
||||
//
|
||||
// ];
|
||||
//
|
||||
// }
|
||||
//
|
||||
// $store_model->saveAll($store_insert);
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(!empty($data['goods_info'])){
|
||||
|
||||
$goods_info = $data['goods_info'];
|
||||
|
||||
unset($data['goods_info']);
|
||||
}
|
||||
|
||||
// if(!empty($data['store_info'])){
|
||||
//
|
||||
// $store_info = $data['store_info'];
|
||||
//
|
||||
// unset($data['store_info']);
|
||||
// }
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(!empty($goods_info)){
|
||||
|
||||
$res = $this->updateSome($dis['id'],$data,$goods_info);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 13:34
|
||||
* @功能说明:积分列表可以通过商品名字查询
|
||||
*/
|
||||
public function dataGoodsList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_shop_goods b','a.goods_id = b.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.goods_name,cover')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 13:54
|
||||
* @功能说明:初始化活动时间
|
||||
*/
|
||||
public function initAtv(){
|
||||
|
||||
$this->where('start_time','>',time())->update(['atv_status'=>1]);
|
||||
|
||||
$this->where('start_time','<',time())->update(['atv_status'=>2]);
|
||||
|
||||
$this->where('end_time','<',time())->update(['atv_status'=>3]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-01 10:18
|
||||
* @功能说明:正在进行中的活动
|
||||
*/
|
||||
public function atvIng($goods_id,$spe_id=0){
|
||||
|
||||
$dis[] = ['a.atv_status','=',2];
|
||||
|
||||
$dis[] = ['a.goods_id','=',$goods_id];
|
||||
|
||||
$dis[] = ['a.status','=',1];
|
||||
|
||||
if(!empty($spe_id)){
|
||||
|
||||
$dis[] = ['b.spe_id','=',$spe_id];
|
||||
}
|
||||
|
||||
// if(!empty($store_id)){
|
||||
//
|
||||
// $dis[] = ['c.store_id','=',$store_id];
|
||||
//
|
||||
// }
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_integral_shop_goods b','a.id = b.atv_id')
|
||||
// ->join('lbfarm_v2_integral_store c','a.id = c.integral_id')
|
||||
->where($dis)
|
||||
->field('a.*,b.*')
|
||||
->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-01 10:18
|
||||
* @功能说明:正在进行中的活动
|
||||
*/
|
||||
public function buyLimit($goods_id,$spe_id=0){
|
||||
|
||||
$dis[] = ['a.atv_status','=',2];
|
||||
|
||||
$dis[] = ['a.goods_id','=',$goods_id];
|
||||
|
||||
$dis[] = ['a.status','=',1];
|
||||
|
||||
if(!empty($spe_id)){
|
||||
|
||||
$dis[] = ['b.spe_id','=',$spe_id];
|
||||
}
|
||||
|
||||
// if(!empty($store_id)){
|
||||
//
|
||||
// $dis[] = ['c.store_id','=',$store_id];
|
||||
//
|
||||
// }
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_integral_shop_goods b','a.id = b.atv_id')
|
||||
// ->join('lbfarm_v2_integral_store c','a.id = c.integral_id')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-04 14:41
|
||||
* @功能说明:获取是否
|
||||
*/
|
||||
public function getBuyLimit($list){
|
||||
|
||||
$this->initAtv();
|
||||
|
||||
$data['buy_limit'] = 1;
|
||||
|
||||
$data['discount_add'] = 1;
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$res = $this->buyLimit($value['goods_id'],$value['spe_id']);
|
||||
|
||||
if(!empty($res)){
|
||||
|
||||
if($res['buy_limit']==0){
|
||||
|
||||
$data['buy_limit'] = 0;
|
||||
}
|
||||
|
||||
if($res['discount_add']==0){
|
||||
|
||||
$data['discount_add'] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-11 16:50
|
||||
* @功能说明:获取活动次数
|
||||
*/
|
||||
public function getAtvNum1($id,$user_id){
|
||||
|
||||
$order_model = new Order();
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.integral_id' => $id,
|
||||
|
||||
'a.user_id' => $user_id
|
||||
|
||||
];
|
||||
|
||||
$num = $order_model->alias('a')
|
||||
->join('longbing_card_v2_shop_order_goods b','a.id = b.order_id')
|
||||
->where('a.pay_type','>=',1)
|
||||
->where($dis)
|
||||
->sum('goods_num');
|
||||
|
||||
return $num;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @return float
|
||||
* 获取历史商品件数
|
||||
*/
|
||||
public function getAtvNum($id,$user_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.integral_id' => $id,
|
||||
|
||||
'b.user_id' => $user_id
|
||||
|
||||
];
|
||||
|
||||
$order_model = new \app\farm\model\ShopOrderGoods();
|
||||
|
||||
//取消订单的不算 chen
|
||||
$num = $order_model->alias('a')
|
||||
->join('lbfarm_shop_order b','a.order_id = b.id')
|
||||
->where($dis)
|
||||
->where('b.pay_type','>=',1)
|
||||
->group('a.id')
|
||||
->sum('a.goods_num');
|
||||
|
||||
|
||||
$order_id = $order_model->alias('a')
|
||||
->join('lbfarm_shop_order b','a.order_id = b.id')
|
||||
->where($dis)
|
||||
->where('b.pay_type','>=',1)
|
||||
->column('b.id');
|
||||
|
||||
$order_refund_goods = new \app\farm\model\ShopRefundGoods();
|
||||
//申请退款成功的
|
||||
$refund_num = $order_refund_goods->where('order_id','in',$order_id)->where(['status'=>2])->sum('goods_num');
|
||||
|
||||
return $num - $refund_num;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-22 11:01
|
||||
* @功能说明:积分商品列表
|
||||
*/
|
||||
public function integralGoodsList($dis,$page=10){
|
||||
|
||||
$goods_model = new ShopGoods();
|
||||
|
||||
$i_goods_model = new IntegralGoods();
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$data = $goods_model->alias('a')
|
||||
->join('lbfarm_v2_integral_shop_goods b','b.goods_id = a.id')
|
||||
->join('lbfarm_v2_integral_shop c','b.atv_id = c.id')
|
||||
->where($dis)
|
||||
->field('a.goods_name,a.cover,a.id as goods_id,c.id as atv_id,c.type')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$spe = $i_goods_model->where(['atv_id'=>$v['atv_id']])->order('price')->find()->toArray();
|
||||
|
||||
$v['integral'] = $spe['integral'];
|
||||
|
||||
$v['price'] = $spe['price'];
|
||||
|
||||
$v['init_price'] = $spe_model->where(['id'=>$spe['spe_id']])->sum('price');
|
||||
|
||||
$v['all_have_stock'] = $i_goods_model->where(['atv_id'=>$v['atv_id']])->sum('have_stock');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
512
app/shop/model/IntegralLog.php
Normal file
512
app/shop/model/IntegralLog.php
Normal file
@@ -0,0 +1,512 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\massage\model\User;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class IntegralLog extends BaseModel
|
||||
{
|
||||
//会员积分表
|
||||
protected $name = 'lbfarm_v2_integral_log';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'create_time_text'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-04 13:57
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getCreateTimeTextAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return date('Y-m-d H:i:s',$data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-07-15 09:49
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function integralAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$data['update_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-07-16 16:35
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function integralList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order(['update_time desc','id desc'])->paginate($page)->toArray();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
if($v['controller_type']==0){
|
||||
|
||||
$v['controller_name'] = '系统核算';
|
||||
|
||||
$icon = $v['integral_add']>0?'+':'-';
|
||||
|
||||
$integral_add = $v['integral_add']>0?$v['integral_add']:$v['integral_add']*-1;
|
||||
|
||||
$text = $v['integral_add']>0?'增加积分':'使用积分';
|
||||
|
||||
$boj = $this->returnObj($v['type']);
|
||||
|
||||
$refund = $v['refund']==1?'(已退款)':'';
|
||||
|
||||
$v['text'] = $boj.$text.$icon.$integral_add.',现积分 '.$v['integral_after'].$refund;
|
||||
|
||||
$v['type_text'] = $boj;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-14 15:17
|
||||
* @功能说明:返回一个对象
|
||||
*/
|
||||
public function returnObj($type){
|
||||
|
||||
switch ($type){
|
||||
|
||||
//加
|
||||
case 1:
|
||||
return '购买商城商品';
|
||||
|
||||
break;
|
||||
//购买储值套餐赠送
|
||||
case 2:
|
||||
return '购买储值套餐';
|
||||
|
||||
break;
|
||||
|
||||
case 3://减
|
||||
return '购买商城商品';
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
return '购买土地产品';
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
return '购买认养产品';
|
||||
|
||||
break;
|
||||
case 6://售后
|
||||
return '商城商品退款';
|
||||
|
||||
break;
|
||||
case 7://售后
|
||||
return '购买养殖产品';
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
return '购买认养配送';
|
||||
|
||||
break;
|
||||
|
||||
case 9:
|
||||
return '购买土地配送';
|
||||
|
||||
break;
|
||||
|
||||
case 10:
|
||||
return '签到';
|
||||
|
||||
break;
|
||||
case 11://消耗
|
||||
return '抽奖';
|
||||
|
||||
break;
|
||||
case 12:
|
||||
return '后台充值';
|
||||
|
||||
break;
|
||||
case 13:
|
||||
return '后台扣除';
|
||||
|
||||
break;
|
||||
|
||||
case 14:
|
||||
return '抽奖获取';
|
||||
|
||||
break;
|
||||
default:
|
||||
return '消费';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-26 17:08
|
||||
* @功能说明:详情
|
||||
*/
|
||||
public function integralInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-26 17:13
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function integralUpdate($dis,$data){
|
||||
|
||||
$data['update_time'] = time();
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-24 10:49
|
||||
* @功能说明:发送积分消息
|
||||
*/
|
||||
public function sendMsg($data,$user_id,$integral,$type){
|
||||
|
||||
if(in_array($type,[1,3,4,5,10,11])){
|
||||
|
||||
$data['integral'] = abs($integral);
|
||||
|
||||
$data['user_id'] = $user_id;
|
||||
//消费获取的积分
|
||||
if(in_array($type,[1,2,4,5])){
|
||||
|
||||
$s_type = 10;
|
||||
|
||||
}elseif (in_array($type,[3])){
|
||||
//消费消耗的积分
|
||||
$s_type = 11;
|
||||
|
||||
}elseif (in_array($type,[11])){
|
||||
//抽奖消耗
|
||||
$s_type = 12;
|
||||
|
||||
}elseif (in_array($type,[10])){
|
||||
//签到获取积分
|
||||
$s_type = 13;
|
||||
|
||||
}
|
||||
|
||||
$info_model = new PushMsgModel($data['uniacid']);
|
||||
|
||||
$info_model->sendMsg($data,$s_type);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-07-31 10:28
|
||||
* @功能说明:增加用户积分
|
||||
*/
|
||||
public function integralUserAdd($user_id,$integral,$uniacid,$status = 2,$type=0,$order_id=0,$time=0,$data=[]){
|
||||
|
||||
// if(!in_array($type,[5,6,7,8])){
|
||||
// //积分倍率
|
||||
// $arr = $this->pointDouble($user_id,$integral);
|
||||
//
|
||||
// $integral = $arr['integral'];
|
||||
// //查询单日获取积分是否超限
|
||||
// $integral = $this->dayGetIntegral($user_id,$integral,$uniacid);
|
||||
// }
|
||||
|
||||
$time = !empty($time)?$time:time();
|
||||
|
||||
if(!empty($integral)&&$integral!='0.00'){
|
||||
//发送消息
|
||||
$this->sendMsg($data,$user_id,$integral,$type);
|
||||
|
||||
$member_model = new \app\farm\model\User();
|
||||
|
||||
$member_info = $member_model->dataInfo(['id'=>$user_id]);
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'integral_add' => $integral,
|
||||
|
||||
'integral_before'=> $member_info['integral'],
|
||||
|
||||
'integral_after' => $member_info['integral']+$integral,
|
||||
|
||||
'status' => $status,
|
||||
|
||||
'type' => $type,
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'double' => !empty($arr['double'])?$arr['double']:1,
|
||||
|
||||
'create_time' => $time,
|
||||
|
||||
'update_time' => $time,
|
||||
];
|
||||
|
||||
$res = $this->insert($insert);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $member_model->dataUpdate(['id'=>$user_id],['integral'=>$insert['integral_after']]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**\
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-12 17:31
|
||||
* @功能说明:积分倍率
|
||||
*/
|
||||
public function pointDouble($user_id,$integral){
|
||||
|
||||
$arr['double'] = 1;
|
||||
|
||||
$arr['integral'] = $integral;
|
||||
|
||||
if($integral<0){
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$member_level = $user_model->where(['id'=>$user_id])->value('member_level');
|
||||
|
||||
|
||||
if(empty($member_level)){
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
$level_model = new Level();
|
||||
|
||||
$level = $level_model->levelInfo(['id'=>$member_level]);
|
||||
|
||||
if(empty($level)){
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
if(empty($level['integral_switch'])){
|
||||
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
$arr['double'] = $level['integral'];
|
||||
|
||||
$arr['integral'] = floor($level['integral']*$integral);
|
||||
|
||||
return $arr;
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-12 14:05
|
||||
* @功能说明:单天获得积分
|
||||
*/
|
||||
public function dayGetIntegral($user_id,$integral,$uniacid){
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$config = $config_model->configInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
if($config['integral_limit']==0){
|
||||
|
||||
return $integral;
|
||||
}
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
|
||||
$dis[] = ['integral_add','>',0];
|
||||
|
||||
$dis[] = ['type','not in',[5,6,7]];
|
||||
//单日获取积分
|
||||
$integral_day = $this->where($dis)->whereDay('create_time')->sum('integral_add');
|
||||
//单日可获取最大积分
|
||||
$integral_day_max = $config['integral_day_max'];
|
||||
|
||||
$point = $integral_day_max-$integral_day;
|
||||
|
||||
if($point<=0){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$point = $point-$integral>0?$integral:$point;
|
||||
|
||||
return $point;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-08-04 10:21
|
||||
* @功能说明:每日领取的积分
|
||||
*/
|
||||
public function dayIntegral($user_id,$uniacid){
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$config = $config_model->configInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
if($config['integral_limit']==1){
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'refund' => 0,
|
||||
|
||||
'type' => 1
|
||||
];
|
||||
|
||||
$integral = $this->where($dis)->where('status','>',0)->whereDay('create_time')->sum('integral_add');
|
||||
|
||||
$re_integral = $config['integral_day_max'] - $integral;
|
||||
|
||||
$re_integral = $re_integral>0?$re_integral:0;
|
||||
|
||||
return intval($re_integral);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-08-04 11:07
|
||||
* @功能说明:给用户加积分
|
||||
*/
|
||||
public function incUserIntegral($order_id,$user_id,$uniacid){
|
||||
|
||||
$dis = [
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$info = $this->where($dis)->select()->toArray();
|
||||
|
||||
$member_model = new Member();
|
||||
|
||||
if(!empty($info)){
|
||||
|
||||
foreach ($info as $value){
|
||||
|
||||
$integral = $value['integral_add'];
|
||||
|
||||
$member_info = $member_model->getMemberInfo(['user_id'=>$user_id,'uniacid'=>$uniacid]);
|
||||
|
||||
$update = [
|
||||
//修改状态
|
||||
'status' => 2,
|
||||
//当前
|
||||
'integral_before' => intval($member_info['integral']),
|
||||
//修改后对
|
||||
'integral_after' => intval($member_info['integral']+$integral),
|
||||
|
||||
];
|
||||
|
||||
$this->integralUpdate(['id'=>$value['id']],$update);
|
||||
|
||||
if(is_numeric($integral)&&$integral>0){
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $user_id
|
||||
|
||||
];
|
||||
|
||||
$member_model->incDecGrowth($dis,$integral,'integral');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
78
app/shop/model/IntegralStore.php
Normal file
78
app/shop/model/IntegralStore.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class IntegralStore extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_integral_store';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
183
app/shop/model/LuckConfig.php
Normal file
183
app/shop/model/LuckConfig.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\Coupon;
|
||||
use think\facade\Db;
|
||||
|
||||
class LuckConfig extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_luck_config';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
|
||||
'coupon_title'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-21 18:03
|
||||
*/
|
||||
public function getCouponTitleAttr($value,$data){
|
||||
|
||||
if(isset($data['coupon_id'])){
|
||||
|
||||
$coupon_model = new Coupon();
|
||||
|
||||
$title = $coupon_model->where(['id'=>$data['coupon_id']])->value('title');
|
||||
|
||||
return $title;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(isset($data['data'])){
|
||||
|
||||
$arr = $data['data'];
|
||||
|
||||
unset($data['data']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($arr)){
|
||||
|
||||
$this->updateSome($id,$arr,$data['uniacid']);
|
||||
|
||||
}
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-15 14:24
|
||||
* @功能说明:添加奖品信息
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$config_model = new LuckConfig();
|
||||
|
||||
$arr = [];
|
||||
|
||||
// $config_model->where(['luck_id'=>$id])->delete();
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$v['uniacid'] = $uniacid;
|
||||
|
||||
$v['luck_id'] = $id;
|
||||
|
||||
if(empty($v['id'])){
|
||||
|
||||
$config_model->insert($v);
|
||||
|
||||
$arr[] = $v['id'];
|
||||
|
||||
}else{
|
||||
|
||||
$config_model->dataUpdate(['id'=>$v['id']],$v);
|
||||
|
||||
$arr[] = $config_model->getLastInsID();
|
||||
|
||||
}
|
||||
|
||||
$config_model->save($v);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$config_model->where(['luck_id'=>$id])->where('id','not in',$arr)->delete();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(isset($data['data'])){
|
||||
|
||||
$arr = $data['data'];
|
||||
|
||||
unset($data['data']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($arr)){
|
||||
|
||||
$this->updateSome($dis['id'],$arr,$data['uniacid']);
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
463
app/shop/model/LuckDraw.php
Normal file
463
app/shop/model/LuckDraw.php
Normal file
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\Coupon;
|
||||
use function GuzzleHttp\Promise\is_settled;
|
||||
use think\facade\Db;
|
||||
|
||||
class LuckDraw extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_luck_draw';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'data'
|
||||
|
||||
];
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-15 14:35
|
||||
*/
|
||||
public function getDataAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$config_model = new LuckConfig();
|
||||
|
||||
$list = $config_model->where(['luck_id'=>$data['id'],'is_luck'=>1])->order('top,id desc')->select()->toArray();
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(isset($data['data'])){
|
||||
|
||||
$arr = $data['data'];
|
||||
|
||||
unset($data['data']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($arr)){
|
||||
|
||||
$this->updateSome($id,$arr,$data['uniacid']);
|
||||
|
||||
}
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-15 14:24
|
||||
* @功能说明:添加奖品信息
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$config_model = new LuckConfig();
|
||||
|
||||
$list = $this->changeData($data,$uniacid,$id);
|
||||
|
||||
$data = array_merge($data,$list);
|
||||
|
||||
$ids = array_column($data,'id');
|
||||
|
||||
$config_model->where(['luck_id'=>$id])->where('id','not in',$ids)->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$v['uniacid'] = $uniacid;
|
||||
|
||||
$v['luck_id'] = $id;
|
||||
|
||||
if(!empty($v['id'])){
|
||||
|
||||
$config_model->dataUpdate(['id'=>$v['id']],$v);
|
||||
|
||||
}else{
|
||||
|
||||
$config_model->insert($v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-26 14:50
|
||||
* @功能说明:
|
||||
*/
|
||||
public function changeData($data,$uniacid,$id){
|
||||
|
||||
$blance = array_sum(array_column($data,'balance'));
|
||||
|
||||
$no_balance = 100-$blance;
|
||||
|
||||
$no_balance = $no_balance>0?ceil($no_balance/count($data)):0;
|
||||
|
||||
for ($i=1;$i<=9;$i++){
|
||||
|
||||
if(!in_array($i,array_column($data,'top'))){
|
||||
|
||||
$arr[] = $i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($arr)){
|
||||
|
||||
foreach ($arr as $key=> $value){
|
||||
|
||||
$list[$key] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'top' => $value,
|
||||
|
||||
'title' => '谢谢参与',
|
||||
|
||||
'is_luck' => 0,
|
||||
|
||||
'balance' => $no_balance,
|
||||
|
||||
'luck_id' => $id,
|
||||
|
||||
'num' => 1
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return !empty($list)?$list:[];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(isset($data['data'])){
|
||||
|
||||
$arr = $data['data'];
|
||||
|
||||
unset($data['data']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($arr)){
|
||||
|
||||
$this->updateSome($dis['id'],$arr,$data['uniacid']);
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $arr
|
||||
* @功能说明:抽奖算法
|
||||
* 根据概率随机中奖
|
||||
*
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-26 14:40
|
||||
*/
|
||||
public function getRand($data){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$arr[$v['id']] = $v['balance'];
|
||||
}
|
||||
|
||||
$sum = array_sum($arr);
|
||||
|
||||
$res = 0;
|
||||
|
||||
foreach ($arr as $key=>$value){
|
||||
|
||||
$rand_num = mt_rand(1,$sum);
|
||||
|
||||
if($rand_num<=$value){
|
||||
|
||||
$res = $key;
|
||||
|
||||
break;
|
||||
}else{
|
||||
|
||||
$sum -= $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 13:54
|
||||
* @功能说明:初始化活动时间
|
||||
*/
|
||||
public function initAtv(){
|
||||
|
||||
$this->where('start_time','>',time())->update(['atv_status'=>1]);
|
||||
|
||||
$this->where('start_time','<',time())->update(['atv_status'=>2]);
|
||||
|
||||
$this->where('end_time','<',time())->update(['atv_status'=>3]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-26 15:04
|
||||
* @功能说明:用户抽奖
|
||||
*/
|
||||
public function luckDraw($atv_id,$user_id,$use_integral,$user_num=0){
|
||||
|
||||
$config_model = new LuckConfig();
|
||||
//获取未中奖的奖项
|
||||
$list = $config_model->where(['luck_id'=>$atv_id])->where('num','>',0)->order('top,id desc')->select()->toArray();
|
||||
|
||||
if(empty($list)){
|
||||
|
||||
return ['code'=>500,'msg'=>'所有奖已被抽完'];
|
||||
}
|
||||
|
||||
$id = $this->getRand($list);
|
||||
|
||||
$data = $config_model->dataInfo(['id'=>$id]);
|
||||
|
||||
$data['times'] = $user_num+1;
|
||||
|
||||
if(empty($data)||($data['is_luck']==1&&$data['num']<=0)){
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
//如果中奖需减数量
|
||||
if($data['is_luck']==1){
|
||||
|
||||
$res = $config_model->dataUpdate(['id'=>$id,'num'=>$data['num']],['num'=>$data['num']-1]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
}
|
||||
}
|
||||
//添加中奖记录
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'atv_id' => $atv_id,
|
||||
|
||||
'type' => $data['type'],
|
||||
|
||||
'coupon_id' => $data['coupon_id'],
|
||||
|
||||
'integral' => $data['integral'],
|
||||
|
||||
'icon' => $data['icon'],
|
||||
|
||||
'title' => $data['title'],
|
||||
|
||||
'is_luck' => $data['is_luck'],
|
||||
|
||||
'use_integral' => $use_integral,
|
||||
|
||||
];
|
||||
|
||||
$record_model = new LuckRecord();
|
||||
|
||||
$i_model = new IntegralLog();
|
||||
|
||||
$res = $record_model->dataAdd($insert);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
|
||||
}
|
||||
$record_id = $record_model->getLastInsID();
|
||||
|
||||
if($data['is_luck']==1){
|
||||
//卡券
|
||||
if($data['type']==1){
|
||||
|
||||
$coupon_model = new Coupon();
|
||||
|
||||
$coupon = $coupon_model->dataInfo(['id'=>$data['coupon_id'],'status'=>1]);
|
||||
|
||||
if(empty($coupon)){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
}
|
||||
|
||||
$coupon_model = new \app\farm\model\CouponRecord();
|
||||
|
||||
$res = $coupon_model->recordAdd($data['coupon_id'],$user_id);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
}
|
||||
|
||||
}else{
|
||||
//积分
|
||||
$res = $i_model->integralUserAdd($user_id,$data['integral'],$data['uniacid'],2,14,$record_id,0,$data);
|
||||
|
||||
if($res==false){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
}
|
||||
}
|
||||
}
|
||||
//积分
|
||||
$res = $i_model->integralUserAdd($user_id,$use_integral*-1,$data['uniacid'],2,11,$record_id,0,$data);
|
||||
|
||||
if($res==false){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
$this->luckDraw($atv_id,$user_id,$use_integral);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $input
|
||||
* @功能说明:校验时间 统一时间段只能有一个活动
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-26 13:46
|
||||
*/
|
||||
public function checkTime($input){
|
||||
|
||||
if(!empty($input['start_time'])){
|
||||
|
||||
$dis[] = ['uniacid','=',$input['uniacid']];
|
||||
|
||||
$dis[] = ['status','>',-1];
|
||||
|
||||
if(!empty($input['id'])){
|
||||
|
||||
$dis[] = ['id','<>',$input['id']];
|
||||
}
|
||||
|
||||
$data = $this->where($dis)->select()->toArray();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $value){
|
||||
|
||||
$res = is_time_cross($input['start_time'],$input['end_time'],$value['start_time'],$value['end_time']);
|
||||
|
||||
if($res==false){
|
||||
|
||||
return ['code'=>500,'msg'=>'该时间段已经有该活动,活动名称:'.$value['title']];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
152
app/shop/model/LuckRecord.php
Normal file
152
app/shop/model/LuckRecord.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\Coupon;
|
||||
use think\facade\Db;
|
||||
|
||||
class LuckRecord extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_luck_record';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-21 18:03
|
||||
*/
|
||||
public function getCouponTitleAttr($value,$data){
|
||||
|
||||
if(isset($data['coupon_id'])){
|
||||
|
||||
$coupon_model = new Coupon();
|
||||
|
||||
$title = $coupon_model->where(['id'=>$data['coupon_id']])->value('title');
|
||||
|
||||
return $title;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-15 14:24
|
||||
* @功能说明:添加奖品信息
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$config_model = new LuckConfig();
|
||||
|
||||
$config_model->where(['luck_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$v['uniacid'] = $uniacid;
|
||||
|
||||
$v['luck_id'] = $id;
|
||||
|
||||
$config_model->insert($v);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-26 16:14
|
||||
* @功能说明:中奖记录
|
||||
*/
|
||||
public function recordList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_user_list b','a.user_id = b.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.nickName,b.avatarurl')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
81
app/shop/model/Member.php
Normal file
81
app/shop/model/Member.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Member extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
//1商品 2商品分类 3土地分类 4 认养分类 5养殖管理
|
||||
protected $name = 'lbfarm_v2_member';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
108
app/shop/model/SeckillConfig.php
Normal file
108
app/shop/model/SeckillConfig.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SeckillConfig extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_seckill_config';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'spe_name'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:54
|
||||
* @功能说明:规格名字
|
||||
*/
|
||||
public function getSpeNameAttr($value,$data){
|
||||
|
||||
if(!empty($data['spe_id'])){
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$info = $spe_model->dataInfo(['id'=>$data['spe_id']]);
|
||||
|
||||
if(!empty($info)){
|
||||
|
||||
return $info['spe_name_text'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
321
app/shop/model/SeckillGoods.php
Normal file
321
app/shop/model/SeckillGoods.php
Normal file
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\ShopGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class SeckillGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_seckill_goods';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'show_data',
|
||||
|
||||
'goods_info',
|
||||
|
||||
'all_stock',
|
||||
|
||||
'all_have_stock',
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:50
|
||||
* @功能说明:总的库存
|
||||
*/
|
||||
public function getAllStockAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$i_model = new SeckillConfig();
|
||||
|
||||
$num = $i_model->where(['atv_id'=>$data['id']])->sum('stock');
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 18:50
|
||||
* @功能说明:总的库存
|
||||
*/
|
||||
public function getAllHaveStockAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$i_model = new SeckillConfig();
|
||||
|
||||
$num = $i_model->where(['atv_id'=>$data['id']])->sum('have_stock');
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-21 18:29
|
||||
*/
|
||||
public function getGoodsInfoAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$config_model = new SeckillConfig();
|
||||
|
||||
$list = $config_model->alias('a')
|
||||
->join('lbfarm_v2_shop_spe_price b','a.spe_id = b.id')
|
||||
->where(['a.atv_id' => $data['id']])
|
||||
->field(['b.stock as goods_stock','b.price as goods_price','a.*'])
|
||||
->select()
|
||||
->toArray();
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-21 14:19
|
||||
*/
|
||||
public function getShowDataAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$config_model = new SeckillConfig();
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$info = $config_model->where(['atv_id'=>$data['id']])->order('price')->find();
|
||||
|
||||
if(!empty($info)){
|
||||
|
||||
$info = $info->toArray();
|
||||
|
||||
$info['init_price'] = $spe_model->where(['id'=>$info['spe_id']])->value('price');
|
||||
|
||||
}
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:商品列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 14:59
|
||||
*/
|
||||
public function goodsList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_shop_goods b','a.goods_id = b.id')
|
||||
->join('lbfarm_v2_goods_store c','c.goods_id = b.id AND c.type=1')
|
||||
->join('lbfarm_farmer d','c.store_id = d.id')
|
||||
->join('lbfarm_v2_seckill_list e','a.atv_id = e.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.goods_name,b.cover,d.title as store_name,d.id as store_id,d.cover as store_cover')
|
||||
->group('a.id')
|
||||
->order('b.top desc,a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 17:19
|
||||
* @功能说明:增加销量
|
||||
*/
|
||||
public function delAtvStock($atv_id,$goods_id,$spe_id,$num){
|
||||
|
||||
$config_model = new SeckillConfig();
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.atv_id' => $atv_id,
|
||||
|
||||
'a.goods_id'=> $goods_id,
|
||||
|
||||
'b.spe_id' => $spe_id
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_seckill_config b','a.id = b.atv_id')
|
||||
->where($dis)
|
||||
->field('b.*')
|
||||
->find();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
return ['code'=>500,'msg'=>'该活动已经下架'];
|
||||
}
|
||||
|
||||
$data = $data->toArray();
|
||||
|
||||
if($data['have_stock']+$num>$data['stock']){
|
||||
|
||||
return ['code'=>500,'msg'=>'可兑换数量不足'];
|
||||
|
||||
}
|
||||
|
||||
$res = $config_model->where(['id'=>$data['id']])->update(['have_stock'=> Db::Raw("have_stock+$num")]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 17:19
|
||||
* @功能说明:减少销量
|
||||
*/
|
||||
public function incAtvStock($atv_id,$goods_id,$spe_id,$num){
|
||||
|
||||
$config_model = new SeckillConfig();
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.atv_id' => $atv_id,
|
||||
|
||||
'a.goods_id'=> $goods_id,
|
||||
|
||||
'b.spe_id' => $spe_id
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_seckill_config b','a.id = b.atv_id')
|
||||
->where($dis)
|
||||
->field('b.*')
|
||||
->find();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$data = $data->toArray();
|
||||
|
||||
$res = $config_model->where(['id'=>$data['id']])->update(['have_stock'=> Db::Raw("have_stock-$num")]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $atv_id
|
||||
* @param $goods_id
|
||||
* @param $spe_id
|
||||
* @param $num
|
||||
* @param int $type
|
||||
* @功能说明:修改活动销量
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 17:47
|
||||
*/
|
||||
public function updateAtvStock($atv_id,$goods_id,$spe_id,$num,$type=1){
|
||||
|
||||
if($type==1){
|
||||
|
||||
$res = $this->delAtvStock($atv_id,$goods_id,$spe_id,$num);
|
||||
|
||||
}else{
|
||||
|
||||
$res = $this->incAtvStock($atv_id,$goods_id,$spe_id,$num);
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
125
app/shop/model/SeckillInfo.php
Normal file
125
app/shop/model/SeckillInfo.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SeckillInfo extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_seckill_info';
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-24 13:52
|
||||
* @功能说明:发送秒杀提醒
|
||||
*/
|
||||
public function sendMsg($uniacid){
|
||||
|
||||
$dis[] = ['a.uniacid','=',$uniacid];
|
||||
|
||||
$dis[] = ['a.status','=',1];
|
||||
|
||||
$dis[] = ['b.status','=',1];
|
||||
|
||||
$dis[] = ['b.atv_status','=',1];
|
||||
|
||||
$dis[] = ['b.start_time','<',time()+120];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_seckill_list b','a.kill_id = b.id')
|
||||
->join('lbfarm_v2_seckill_goods c','c.atv_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$push_model = new PushMsgModel($uniacid);
|
||||
|
||||
foreach ($data as $v){
|
||||
|
||||
$this->dataUpdate(['id'=>$v['id']],['status'=>2]);
|
||||
|
||||
$v['id'] = $v['goods_id'];
|
||||
|
||||
$push_model->sendMsg($v,15);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
374
app/shop/model/SeckillList.php
Normal file
374
app/shop/model/SeckillList.php
Normal file
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\ShopGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class SeckillList extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_seckill_list';
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 15:43
|
||||
* @功能说明:检查活动时间
|
||||
*/
|
||||
public function atvCheck($input){
|
||||
|
||||
$dis[] = ['uniacid','=',$input['uniacid']];
|
||||
|
||||
$dis[] = ['status','>',-1];
|
||||
|
||||
if(!empty($input['id'])){
|
||||
|
||||
$dis[] = ['id','<>',$input['id']];
|
||||
|
||||
}
|
||||
|
||||
$list = $this->where($dis)->select()->toArray();
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$res = is_time_cross($input['start_time'],$input['end_time'],$value['start_time'],$value['end_time']);
|
||||
|
||||
if($res==false){
|
||||
|
||||
return ['code'=>500,'msg'=>'该时间段已经有该活动,活动名称:'.$value['title']];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uniacid
|
||||
* @param $config
|
||||
* @param $store
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-15 16:11
|
||||
*/
|
||||
public function updateSome($id,$uniacid,$spe,$goods_id){
|
||||
|
||||
$config_model = new SeckillConfig();
|
||||
|
||||
$goods_model = new SeckillGoods();
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'atv_id' => $id,
|
||||
|
||||
'goods_id'=> $goods_id
|
||||
];
|
||||
|
||||
$find = $goods_model->dataInfo($insert);
|
||||
|
||||
if(empty($find)){
|
||||
|
||||
$goods_model->dataAdd($insert);
|
||||
|
||||
$atv_id = $goods_model->getLastInsID();
|
||||
|
||||
}else{
|
||||
|
||||
$atv_id = $find['id'];
|
||||
|
||||
}
|
||||
|
||||
if(!empty($spe)){
|
||||
|
||||
foreach ($spe as $value){
|
||||
|
||||
$i_dis = [
|
||||
|
||||
'atv_id' => $id,
|
||||
|
||||
'goods_id'=> $goods_id,
|
||||
|
||||
'spe_id' => $value['spe_id'],
|
||||
];
|
||||
|
||||
$have_stock = $config_model->where($i_dis)->sum('have_stock');
|
||||
|
||||
$value['uniacid'] = $uniacid;
|
||||
|
||||
$value['atv_id'] = $atv_id;
|
||||
|
||||
$value['have_stock'] = $have_stock;
|
||||
|
||||
$config_model->insert($value);
|
||||
|
||||
$arr[] = $config_model->getLastInsID();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$config_model->where(['atv_id'=>$atv_id])->where('id','not in',$arr)->delete();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-29 13:54
|
||||
* @功能说明:初始化活动时间
|
||||
*/
|
||||
public function initAtv(){
|
||||
|
||||
$this->where('start_time','>',time())->update(['atv_status'=>1]);
|
||||
|
||||
$this->where('start_time','<',time())->update(['atv_status'=>2]);
|
||||
|
||||
$this->where('end_time','<',time())->update(['atv_status'=>3]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-01 10:18
|
||||
* @功能说明:正在进行中的活动
|
||||
*/
|
||||
public function atvIng($goods_id,$spe_id=0,$type=1){
|
||||
|
||||
$this->initAtv();
|
||||
|
||||
if($type==1){
|
||||
|
||||
$dis[] = ['a.atv_status','=',2];
|
||||
|
||||
}else{
|
||||
|
||||
$dis[] = ['a.atv_status','in',[1,2]];
|
||||
|
||||
}
|
||||
|
||||
$dis[] = ['b.goods_id','=',$goods_id];
|
||||
|
||||
$dis[] = ['a.status','=',1];
|
||||
|
||||
if(!empty($spe_id)){
|
||||
|
||||
$dis[] = ['c.spe_id','=',$spe_id];
|
||||
}
|
||||
|
||||
// $dis[] = ['c.store_id','=',$store_id];
|
||||
//
|
||||
// $dis[] = ['c.type','=',6];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_seckill_goods b','a.id = b.atv_id')
|
||||
->join('lbfarm_v2_seckill_config c','b.id = c.atv_id')
|
||||
// ->join('lbfarm_v2_goods_store c','a.id = c.goods_id')
|
||||
->where($dis)
|
||||
->field('b.*,a.*,c.price,c.spe_id,c.stock,c.have_stock,a.id as kill_atv_id')
|
||||
->order('c.price')
|
||||
->find();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$data = $data->toArray();
|
||||
//减去已经销售的
|
||||
$data['stock'] = ($data['stock'] - $data['have_stock'])>0?$data['stock'] - $data['have_stock']:0;
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$data['init_price'] = $spe_model->where(['id'=>$data['spe_id']])->value('price');
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-04 14:41
|
||||
* @功能说明:获取是否
|
||||
*/
|
||||
public function getBuyLimit($list,$store_id=0){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$res = $this->atvIng($value['goods_id'],$value['spe_id']);
|
||||
|
||||
if(!empty($res)){
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-28 15:58
|
||||
* @功能说明:校验用户是否可以参加秒杀
|
||||
*/
|
||||
public function userCheck($user_id,$atv_id,$is_show){
|
||||
|
||||
if(empty($atv_id)){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!empty($atv_id)&&$is_show!=2){
|
||||
|
||||
return ['code'=>500,'msg'=>'秒杀商品不能从购物车下单哦'];
|
||||
}
|
||||
|
||||
$atv = $this->dataInfo(['id'=>$atv_id]);
|
||||
|
||||
if(empty($atv)){
|
||||
|
||||
return ['code'=>500,'msg'=>'秒杀活动已结束'];
|
||||
|
||||
}
|
||||
|
||||
if($atv['is_limit']==1){
|
||||
|
||||
$num = $this->getAtvNum($atv_id,$user_id);
|
||||
|
||||
if($num>=$atv['limit_num']){
|
||||
|
||||
return ['code'=>500,'msg'=>'超过秒杀次数'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @return float
|
||||
* 获取历史商品件数
|
||||
*/
|
||||
public function getAtvNum($id,$user_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.kill_atv_id' => $id,
|
||||
|
||||
'b.user_id' => $user_id
|
||||
|
||||
];
|
||||
|
||||
$order_model = new \app\farm\model\ShopOrderGoods();
|
||||
//取消订单的不算 chen
|
||||
$num = $order_model->alias('a')
|
||||
->join('lbfarm_shop_order b','a.order_id = b.id')
|
||||
->where($dis)
|
||||
->where('b.pay_type','>=',1)
|
||||
->group('a.id')
|
||||
->sum('a.goods_num');
|
||||
|
||||
|
||||
$order_id = $order_model->alias('a')
|
||||
->join('lbfarm_shop_order b','a.order_id = b.id')
|
||||
->where($dis)
|
||||
->where('b.pay_type','>=',1)
|
||||
->column('b.id');
|
||||
|
||||
$order_refund_goods = new \app\farm\model\ShopRefundGoods();
|
||||
//申请退款成功的
|
||||
$refund_num = $order_refund_goods->where('order_id','in',$order_id)->where(['status'=>2])->sum('goods_num');
|
||||
|
||||
return $num - $refund_num;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
206
app/shop/model/ShopGoodsCate.php
Normal file
206
app/shop/model/ShopGoodsCate.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\ShopGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopGoodsCate extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_goods_cate';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'goods_num',
|
||||
|
||||
'store'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-04 17:23
|
||||
*/
|
||||
public function getStoreAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.status' => 2,
|
||||
|
||||
'a.goods_id' => $data['id'],
|
||||
|
||||
'a.type' => 2
|
||||
];
|
||||
|
||||
$store_goods_model = new StoreGoods();
|
||||
|
||||
$list = $store_goods_model->alias('a')
|
||||
->join('lbfarm_farmer b','a.store_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.title')
|
||||
->group('a.id')
|
||||
->order('a.id dsec')
|
||||
->column('b.id');
|
||||
|
||||
return array_values($list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 13:46
|
||||
* @功能说明:分类下面端商品数量
|
||||
*/
|
||||
public function getGoodsNumAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$goods_model = new ShopGoods();
|
||||
|
||||
$num = $goods_model->where(['cate_id'=>$data['id']])->where('status','>',-1)->count();
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(!empty($data['store'])){
|
||||
|
||||
$store = $data['store'];
|
||||
|
||||
unset($data['store']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($store)){
|
||||
|
||||
$this->updateSome($id,$store,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @param $uniacid
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-04 14:47
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$store_goods_model = new StoreGoods();
|
||||
|
||||
$store_goods_model->where(['goods_id'=>$id,'type'=>2])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'store_id'=> $v,
|
||||
|
||||
'goods_id'=> $id,
|
||||
|
||||
'type' => 2
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$store_goods_model->saveAll($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(!empty($data['store'])){
|
||||
|
||||
$store = $data['store'];
|
||||
|
||||
unset($data['store']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($store)){
|
||||
|
||||
$this->updateSome($dis['id'],$store,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
135
app/shop/model/ShopGoodsSpe.php
Normal file
135
app/shop/model/ShopGoodsSpe.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopGoodsSpe extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_shop_spe';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-06-12 15:28
|
||||
*/
|
||||
public function getImageAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return $value;
|
||||
}else{
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @return mixed
|
||||
* 获取多规格
|
||||
*/
|
||||
public function goodsSpe($dis){
|
||||
$data = $this->where($dis)->select()->toArray();
|
||||
return $this->getTree($data,0);
|
||||
}
|
||||
/**
|
||||
* @param $data
|
||||
* @param $pId
|
||||
* @return array
|
||||
* 递归无限极
|
||||
*/
|
||||
public function getTree($data, $pId){
|
||||
$tree = array();
|
||||
if(!empty($data)){
|
||||
foreach($data as $k => $v) {
|
||||
if($v['pid'] == $pId) {
|
||||
$v['cate'] = $this->getTree($data, $v['id']);
|
||||
$tree[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 添加商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpeAdd($data){
|
||||
$data['create_time'] = time();
|
||||
$data['status'] = 1;
|
||||
$res = $this->insert($data);
|
||||
$res = $this->getLastInsID();
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int|string
|
||||
* 添加商品规格
|
||||
*/
|
||||
|
||||
public function goodsSpeUpdate($dis,$data){
|
||||
$data['update_time'] = time();
|
||||
$res = $this->where($dis)->update($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* 根据条件获取id
|
||||
*/
|
||||
|
||||
public function goodsSpeId($dis){
|
||||
$data = $this->where($dis)->column('id');
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\exception\DbException
|
||||
* 获取一个
|
||||
*/
|
||||
public function getSinge($dis){
|
||||
$data = $this->where($dis)->find();
|
||||
return !empty($data)?$data->toArray():$data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @return mixed
|
||||
* 获取多规格
|
||||
*/
|
||||
public function goodsSpeNot($dis,$data){
|
||||
$data = $this->where($dis)->where('pid','not in',$data)->select()->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* 获取多规格的pid
|
||||
*/
|
||||
public function goodSpePid($dis){
|
||||
$data = $this->where($dis)->value('pid');
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1142
app/shop/model/ShopOrder.php
Normal file
1142
app/shop/model/ShopOrder.php
Normal file
File diff suppressed because it is too large
Load Diff
263
app/shop/model/ShopOrderGoods.php
Normal file
263
app/shop/model/ShopOrderGoods.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopOrderGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_order_goods';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'refund_num',
|
||||
|
||||
'refund_ing'
|
||||
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:是否退款中
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-12 10:46
|
||||
*/
|
||||
public function getRefundIngAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$refund_model = new ShopRefund();
|
||||
|
||||
$res = $refund_model->orderRefundIng($data['id']);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取退款的数量
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-12 10:46
|
||||
*/
|
||||
public function getRefundNumAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$refund_model = new ShopRefund();
|
||||
|
||||
$num = $refund_model->refundNum($data['id']);
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataSelect($dis){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->select()->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-22 11:12
|
||||
* @功能说明:添加商品子订单
|
||||
*/
|
||||
public function orderGoodsAdd($order_goods,$order_id,$user_id,$store_id){
|
||||
|
||||
$goods_model = new ShopGoods();
|
||||
|
||||
$car_model = new Car();
|
||||
|
||||
foreach ($order_goods as $v){
|
||||
// //限购
|
||||
// if($v['is_limit']==2){
|
||||
// //已购数量
|
||||
// $buy_num = $this->getGoodsNumber(['b.user_id'=>$user_id,'a.goods_id'=>$v['goods_id']]);
|
||||
//
|
||||
// if($v['limit']<$buy_num+$v['goods_num']){
|
||||
//
|
||||
// return ['code'=>500,'msg'=>$v['name'].'超出限购数量,限购数量'.$v['limit']];
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $v['uniacid'],
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'pay_type' => 1,
|
||||
|
||||
'goods_name' => $v['goods_name'],
|
||||
|
||||
'goods_cover' => $v['cover'],
|
||||
|
||||
'spe_name' => $v['spe_name'],
|
||||
|
||||
'goods_price' => $v['price'],
|
||||
|
||||
'pay_price' => $v['true_price'],
|
||||
|
||||
'singe_pay_price'=> $v['true_price']/$v['goods_num'],
|
||||
|
||||
'goods_num' => $v['goods_num'],
|
||||
|
||||
'can_refund_num' => $v['goods_num'],
|
||||
|
||||
'spe_id' => $v['spe_id'],
|
||||
|
||||
'goods_id' => $v['goods_id'],
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'下单失败'];
|
||||
}
|
||||
//减少库存 增加销量
|
||||
$res = $goods_model->setOrDelStock($v['goods_id'],$v['spe_id'],$v['goods_num'],0,0);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
return $res;
|
||||
}
|
||||
//删除购物车
|
||||
$dis = [
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'status' => 1,
|
||||
|
||||
'goods_id'=> $v['goods_id'],
|
||||
|
||||
'spe_id' => $v['spe_id'],
|
||||
|
||||
'farmer_id' => $store_id
|
||||
];
|
||||
|
||||
$res = $car_model->where($dis)->delete();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @return float
|
||||
* 获取历史商品件数
|
||||
*/
|
||||
public function getGoodsNumber($dis){
|
||||
|
||||
//取消订单的不算 chen
|
||||
$num = $this->alias('a')
|
||||
->join('longbing_card_v2_shop_order_list b','a.order_id = b.id')
|
||||
->where($dis)
|
||||
->where('b.pay_type','>=',1)
|
||||
->group('a.id')
|
||||
->sum('a.goods_num');
|
||||
|
||||
|
||||
$order_id = $this->alias('a')
|
||||
->join('longbing_card_v2_shop_order_list b','a.order_id = b.id')
|
||||
->where($dis)
|
||||
->where('b.pay_type','>=',1)
|
||||
->column('b.id');
|
||||
|
||||
$order_refund_goods = new RefundOrderGoods();
|
||||
//申请退款成功的
|
||||
$refund_num = $order_refund_goods->where('order_id','in',$order_id)->where(['status'=>2])->sum('goods_num');
|
||||
|
||||
return $num - $refund_num;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
899
app/shop/model/ShopRefund.php
Normal file
899
app/shop/model/ShopRefund.php
Normal file
@@ -0,0 +1,899 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\admin\model\ShopOrderRefund;
|
||||
use app\BaseModel;
|
||||
use app\farm\model\BalanceWater;
|
||||
|
||||
use app\massage\model\CouponRecord;
|
||||
use app\massage\model\User;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopRefund extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_refund_order';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'order_goods',
|
||||
|
||||
'address_info',
|
||||
|
||||
'all_goods_num',
|
||||
|
||||
'store_info',
|
||||
|
||||
'refund_user_name'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-08 14:35
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getRefundUserNameAttr($value,$data){
|
||||
|
||||
if(isset($data['refund_user'])&&isset($data['refund_user_admin'])){
|
||||
|
||||
if($data['refund_user_admin']==1){
|
||||
|
||||
$model = new Admin();
|
||||
|
||||
$info = $model->where(['id'=>$data['refund_user']])->value('username');
|
||||
|
||||
}else{
|
||||
|
||||
$model = new \app\farm\model\User();
|
||||
|
||||
$info = $model->where(['id'=>$data['refund_user']])->value('nickName');
|
||||
|
||||
}
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-07 17:38
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getStoreInfoAttr($value,$data){
|
||||
|
||||
if(!empty($data['store_id'])){
|
||||
|
||||
$farmer_model= new Farmer();
|
||||
|
||||
$info = $farmer_model->dataInfo(['id'=>$data['store_id'],'type'=>2]);
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-26 16:48
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:总商品数量
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-25 14:39
|
||||
*/
|
||||
public function getAllGoodsNumAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$order_goods_model = new ShopRefundGoods();
|
||||
|
||||
$dis = [
|
||||
|
||||
'refund_id' => $data['id']
|
||||
];
|
||||
|
||||
$num = $order_goods_model->where($dis)->sum('goods_num');
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-17 17:16
|
||||
* @功能说明:收货信息
|
||||
*/
|
||||
public function getAddressInfoAttr($value,$data){
|
||||
|
||||
if(!empty($data['order_id'])){
|
||||
|
||||
$address_model = new OrderAddress();
|
||||
|
||||
$info = $address_model->dataInfo(['order_id'=>$data['order_id']]);
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-17 17:16
|
||||
* @功能说明:收货信息
|
||||
*/
|
||||
public function getOrderGoodsAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$goods_model = new ShopRefundGoods();
|
||||
|
||||
$info = $goods_model->dataSelect(['refund_id'=>$data['id']]);
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-15 14:37
|
||||
* @功能说明:后台列表
|
||||
*/
|
||||
public function adminDataList($dis,$page=10,$mapor=[]){
|
||||
|
||||
$data = $this->alias('a')
|
||||
|
||||
->join('lbfarm_shop_refund_order_goods c','a.id = c.refund_id')
|
||||
->join('lbfarm_shop_order d','a.order_id = d.id')
|
||||
->join('lbfarm_order_address e','a.order_id = e.order_id AND type = 5','left')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($mapor){
|
||||
$query->whereOr($mapor);
|
||||
})
|
||||
->field('a.*,e.mobile,d.order_code as pay_order_code,e.user_name,d.pay_price')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['nickName'] = $user_model->where(['id'=>$v['user_id']])->value('nickName');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 17:46
|
||||
* @功能说明:小程序退款列表
|
||||
*/
|
||||
public function indexDataList($dis,$where=[],$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_shop_refund_order_goods c','a.id = c.refund_id')
|
||||
->join('lbfarm_shop_order d','a.order_id = d.id')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->field('a.*,d.order_code as pay_order_code')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-08 17:08
|
||||
* @功能说明:退款中
|
||||
*/
|
||||
public function refundIng($cap_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'cap_id' => $cap_id,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$count = $this->where($dis)->count();
|
||||
|
||||
return $count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['status'] = 1;
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 09:37
|
||||
* @功能说明:通过退款
|
||||
*/
|
||||
public function passOrder($id,$price,$payConfig,$refund_user=0,$text='',$id_admin=0){
|
||||
|
||||
$refund_order= $this->dataInfo(['id'=>$id]);
|
||||
|
||||
$order_model = new ShopOrder();
|
||||
|
||||
$pay_order = $order_model->dataInfo(['id'=>$refund_order['order_id']]);
|
||||
|
||||
if($refund_order['status']!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'订单状态错误'];
|
||||
}
|
||||
|
||||
$update = [
|
||||
|
||||
'refund_user' => $refund_user,
|
||||
|
||||
'status' => 2,
|
||||
|
||||
'refund_time' => time(),
|
||||
|
||||
'refund_price'=> $price,
|
||||
|
||||
'pay_price' => $price,
|
||||
|
||||
'refund_text' => $text,
|
||||
|
||||
'refund_user_admin' => $id_admin
|
||||
];
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$refund_order['id']],$update);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败,请重试'];
|
||||
|
||||
}
|
||||
//修改退款子订单的退款状态
|
||||
$order_refund_goods = new ShopRefundGoods();
|
||||
|
||||
$res = $order_refund_goods->dataUpdate(['refund_id'=>$id],['status'=>2]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败,请重试1'.$res];
|
||||
|
||||
}
|
||||
|
||||
$goods_model = new ShopGoods();
|
||||
//退换库存
|
||||
foreach ($refund_order['order_goods'] as $v){
|
||||
|
||||
$res = $goods_model->setOrDelStock($v['goods_id'],$v['spe_id'],$v['goods_num'],1,1);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$res = $order_model->dataUpdate(['id'=>$refund_order['order_id']],['true_price'=>$pay_order['true_price']-$price]);
|
||||
//查看货是否退完了
|
||||
$refund_success = $this->checkRefundNum($refund_order['order_id']);
|
||||
//退完了 就修改订单状态
|
||||
if($refund_success==1){
|
||||
|
||||
$res = $order_model->dataUpdate(['id'=>$refund_order['order_id']],['pay_type'=>-1]);
|
||||
//退换优惠券
|
||||
$coupon_model = new CouponRecord();
|
||||
//
|
||||
// $coupon_model->couponRefund($pay_order['id'],2);
|
||||
// if($res==0){
|
||||
//
|
||||
// Db::rollback();
|
||||
//
|
||||
// return ['code'=>500,'msg'=>'退款失败,请重试2'];
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
$pay_order = $order_model->dataInfo(['id'=>$refund_order['order_id']]);
|
||||
|
||||
$refund_order= $this->dataInfo(['id'=>$id]);
|
||||
|
||||
$res = $this->refundCash($payConfig,$pay_order,$price,$refund_order);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>$res['msg']];
|
||||
}
|
||||
|
||||
if($res!=true){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败,请重试3'];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $payConfig
|
||||
* @param $pay_order
|
||||
* @param $price
|
||||
* @param int $refund_id
|
||||
* @功能说明:退钱
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-12 20:31
|
||||
*/
|
||||
public function refundCash($payConfig,$pay_order,$price,$refund_order){
|
||||
|
||||
if($price<=0){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$water_model = new FinanceWater();
|
||||
//说明订单已经完成
|
||||
if($pay_order['type']=-1){
|
||||
//将流水状态修改为可入账
|
||||
$water_model->dataUpdate(['order_id'=>$pay_order['id'],'type'=>8],['cash_status'=>1]);
|
||||
//增加退款流水
|
||||
$water_model->addWater($refund_order['id'],9,2,1);
|
||||
//如果有运费将运费也改为可入账
|
||||
$water_model->dataUpdate(['order_id'=>$pay_order['id'],'type'=>16],['cash_status'=>1]);
|
||||
//增加运费退款流水
|
||||
$water_model->addWater($refund_order['id'],17,1,1);
|
||||
|
||||
}else{
|
||||
|
||||
$water_model->addWater($refund_order['id'],9,2,0);
|
||||
|
||||
$water_model->addWater($refund_order['id'],17,1,0);
|
||||
|
||||
}
|
||||
|
||||
$water_model->cashArrival();
|
||||
|
||||
if(empty($pay_order['balance'])){
|
||||
//微信退款
|
||||
$response = orderRefundApi($payConfig,$pay_order['pay_price'],$price,$pay_order['transaction_id']);
|
||||
//如果退款成功修改一下状态
|
||||
if ( isset( $response[ 'return_code' ] ) && isset( $response[ 'result_code' ] ) && $response[ 'return_code' ] == 'SUCCESS' && $response[ 'result_code' ] == 'SUCCESS' ) {
|
||||
|
||||
$response['out_refund_no'] = !empty($response['out_refund_no'])?$response['out_refund_no']:$pay_order['order_code'];
|
||||
|
||||
$this->dataUpdate(['id'=>$refund_order['id']],['out_refund_no'=>$response['out_refund_no']]);
|
||||
|
||||
}else {
|
||||
//失败就报错
|
||||
$discption = !empty($response['err_code_des'])?$response['err_code_des']:$response['return_msg'];
|
||||
|
||||
return ['code'=>500,'msg'=> $discption];
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$data = [
|
||||
|
||||
'user_id' => $pay_order['user_id'],
|
||||
|
||||
'pay_price'=> $price,
|
||||
|
||||
'id' => $refund_order['id'],
|
||||
|
||||
'uniacid' => $pay_order['uniacid']
|
||||
];
|
||||
|
||||
$water_model = new \app\farm\model\BalanceWater();
|
||||
|
||||
$res = $water_model->addWater($data,10,1);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 10:29
|
||||
* @功能说明:检查改订单款退完了没
|
||||
*/
|
||||
public function checkRefundNum($order_id,$status=2){
|
||||
|
||||
$order_goods_model = new ShopOrderGoods();
|
||||
|
||||
$order_refund_goods_model = new ShopRefundGoods();
|
||||
|
||||
$dis = [
|
||||
|
||||
'order_id' => $order_id
|
||||
];
|
||||
|
||||
$goods_num = $order_goods_model->where($dis)->sum('goods_num');
|
||||
|
||||
if($status==2){
|
||||
|
||||
$dis['status'] = 2;
|
||||
|
||||
$refund_num= $order_refund_goods_model->where($dis)->sum('goods_num');
|
||||
}else{
|
||||
|
||||
$refund_num= $order_refund_goods_model->where($dis)->where('status','in',[1,2])->sum('goods_num');
|
||||
}
|
||||
|
||||
return $refund_num>=$goods_num?1:0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 15:38
|
||||
* @功能说明:该天的退款
|
||||
*/
|
||||
public function datePrice($date,$uniacid,$cap_id=0,$end_time='',$type=1){
|
||||
|
||||
$end_time = !empty($end_time)?$end_time:$date+86399;
|
||||
|
||||
$dis = [];
|
||||
|
||||
$dis[] = ['status','=',2];
|
||||
|
||||
$dis[] = ['create_time','between',"$date,$end_time"];
|
||||
|
||||
$dis[] = ['uniacid',"=",$uniacid];
|
||||
|
||||
if(!empty($cap_id)){
|
||||
|
||||
$dis[] = ['cap_id','=',$cap_id];
|
||||
}
|
||||
|
||||
if($type==1){
|
||||
|
||||
$price = $this->where($dis)->sum('refund_price');
|
||||
|
||||
return round($price,2);
|
||||
|
||||
}else{
|
||||
|
||||
$count = $this->where($dis)->count();
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-26 13:33
|
||||
* @功能说明:申请退款
|
||||
*/
|
||||
public function applyRefund($order,$input){
|
||||
|
||||
$order_goods_model = new ShopOrderGoods();
|
||||
|
||||
$refund_price = 0;
|
||||
|
||||
$integral = 0;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$list = $input['list'];
|
||||
|
||||
foreach ($list as $k=>$value){
|
||||
|
||||
$order_goods = $order_goods_model->dataInfo(['id'=>$value['id']]);
|
||||
|
||||
if(empty($order_goods)){
|
||||
|
||||
return ['code'=>500,'msg'=>'商品未找到'];
|
||||
}
|
||||
|
||||
if($value['num']>$order_goods['can_refund_num']||$value['num']==0){
|
||||
|
||||
return ['code'=>500,'msg'=>'退款数量错误'];
|
||||
|
||||
}
|
||||
//退款金额
|
||||
$refund_price += $order_goods['singe_pay_price']*$value['num'];
|
||||
|
||||
|
||||
$list[$k]['goods_id'] = $order_goods['goods_id'];
|
||||
|
||||
$list[$k]['goods_name'] = $order_goods['goods_name'];
|
||||
|
||||
$list[$k]['goods_cover'] = $order_goods['goods_cover'];
|
||||
|
||||
$list[$k]['spe_name'] = $order_goods['spe_name'];
|
||||
|
||||
$list[$k]['spe_id'] = $order_goods['spe_id'];
|
||||
|
||||
$list[$k]['goods_price'] = $order_goods['goods_price'];
|
||||
|
||||
$res = $order_goods_model->where(['id'=>$value['id']])->update(['can_refund_num'=>$order_goods['can_refund_num']-$value['num']]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'申请失败'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if($refund_price<=0){
|
||||
//
|
||||
// Db::rollback();
|
||||
//
|
||||
// return ['code'=>500,'msg'=>'退款金额至少为0.01元'];
|
||||
// }
|
||||
|
||||
$refund_price = round($refund_price,2);
|
||||
|
||||
$refund_price = $refund_price<=$order['pay_price']?$refund_price:$order['pay_price'];
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'store_id' => $order['store_id'],
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'farmer_id' => $order['farmer_id'],
|
||||
|
||||
'order_code' => orderCode(),
|
||||
|
||||
'apply_price'=> $refund_price,
|
||||
|
||||
'order_id' => $order['id'],
|
||||
|
||||
'text' => $input['text'],
|
||||
|
||||
'imgs' => !empty($input['imgs'])?implode(',',$input['imgs']):''
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'申请失败'];
|
||||
|
||||
}
|
||||
|
||||
$refund_id = $this->getLastInsID();
|
||||
|
||||
$refund_goods_model = new ShopRefundGoods();
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'order_id' => $order['id'],
|
||||
|
||||
'refund_id' => $refund_id,
|
||||
|
||||
'order_goods_id' => $value['id'],
|
||||
|
||||
'goods_id' => $value['goods_id'],
|
||||
|
||||
'goods_name' => $value['goods_name'],
|
||||
|
||||
'goods_cover' => $value['goods_cover'],
|
||||
|
||||
'spe_name' => $value['spe_name'],
|
||||
|
||||
'spe_id' => $value['spe_id'],
|
||||
|
||||
'goods_num' => $value['num'],
|
||||
|
||||
'goods_price' => $value['goods_price'],
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$res = $refund_goods_model->dataAdd($insert);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'申请失败'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//查看货是否退完了
|
||||
$refund_success = $this->checkRefundNum($order['id'],1);
|
||||
//退完并且未发货 就退运费
|
||||
if($refund_success==1&&$order['pay_type']<3){
|
||||
|
||||
$refund_price += $order['freight'];
|
||||
|
||||
$refund_price = $refund_price<=$order['pay_price']?$refund_price:$order['pay_price'];
|
||||
|
||||
$this->dataUpdate(['id'=>$refund_id],['apply_price'=>$refund_price,'car_price'=>$order['freight']]);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return $refund_id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-12 09:23
|
||||
* @功能说明:获取订单已经退款的数量
|
||||
*/
|
||||
public function refundNum($order_goods_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.order_goods_id' => $order_goods_id,
|
||||
|
||||
'a.status' => 2
|
||||
];
|
||||
|
||||
$num = $this->alias('a')
|
||||
->join('lbfarm_shop_refund_order_goods b','a.id = b.refund_id')
|
||||
->where($dis)
|
||||
->group('b.order_goods_id')
|
||||
->sum('b.goods_num');
|
||||
|
||||
return $num;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-12 09:23
|
||||
* @功能说明:获取订单已经退款的数量
|
||||
*/
|
||||
public function orderRefundIng($order_goods_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.order_goods_id' => $order_goods_id,
|
||||
|
||||
'a.status' => 1
|
||||
];
|
||||
|
||||
$num = $this->alias('a')
|
||||
->join('lbfarm_shop_refund_order_goods b','a.id = b.refund_id')
|
||||
->where($dis)
|
||||
->group('b.order_goods_id')
|
||||
->find();
|
||||
|
||||
return !empty($num)?1:0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-12 12:04
|
||||
* @功能说明:拒绝退款
|
||||
*/
|
||||
public function noPassRefund($refund_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $refund_id
|
||||
];
|
||||
|
||||
$refund_order = $this->dataInfo($dis);
|
||||
|
||||
if($refund_order['status']!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'退款状态错误'];
|
||||
|
||||
}
|
||||
|
||||
$update = [
|
||||
|
||||
'status' => 3,
|
||||
|
||||
'refund_time' => time()
|
||||
|
||||
];
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->dataUpdate($dis,$update);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败,请重试1'];
|
||||
|
||||
}
|
||||
//修改退款子订单的退款状态
|
||||
$order_refund_goods = new ShopRefundGoods();
|
||||
|
||||
$res = $order_refund_goods->dataUpdate(['refund_id'=>$refund_id],['status'=>3]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败,请重试2'];
|
||||
|
||||
}
|
||||
//查询通支付订单未退款对售后订单
|
||||
$where[] = ['order_id','=',$refund_order['order_id']];
|
||||
|
||||
$where[] = ['status','=',1];
|
||||
|
||||
$where[] = ['car_price','>',0];
|
||||
|
||||
$find = $this->dataInfo($where);
|
||||
|
||||
if(!empty($find)){
|
||||
|
||||
$apply_price = $find['apply_price'] - $find['car_price'];
|
||||
|
||||
$apply_price = $apply_price>0?$apply_price:0;
|
||||
|
||||
$update = [
|
||||
|
||||
'apply_price' => $apply_price,
|
||||
|
||||
'car_price' => 0
|
||||
];
|
||||
|
||||
$this->dataUpdate(['id'=>$find['id']],$update);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
116
app/shop/model/ShopRefundGoods.php
Normal file
116
app/shop/model/ShopRefundGoods.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopRefundGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_refund_order_goods';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'pay_price'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-17 14:10
|
||||
* @功能说明:获取商品实付价格
|
||||
*/
|
||||
public function getPayPriceAttr($value,$data){
|
||||
|
||||
if(!empty($data['order_goods_id'])){
|
||||
|
||||
$order_goods_model = new ShopOrderGoods();
|
||||
|
||||
$price = $order_goods_model->where(['id'=>$data['order_goods_id']])->sum('singe_pay_price');
|
||||
|
||||
return $price;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataSelect($dis){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->select()->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
102
app/shop/model/Signin.php
Normal file
102
app/shop/model/Signin.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Signin extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_signin';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
$this->dataAdd($dis);
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
}
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-24 11:45
|
||||
* @功能说明:发送提醒消息
|
||||
*/
|
||||
public function sendMsg($uniacid){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
185
app/shop/model/SigninRecord.php
Normal file
185
app/shop/model/SigninRecord.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\User;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SigninRecord extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_signin_record';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'create_time_text'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 11:37
|
||||
*/
|
||||
public function getCreateTimeTextAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return date('Y-m-d H:i',$data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page=10){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-22 16:11
|
||||
* @功能说明:判断是否是连续签到
|
||||
*/
|
||||
public function initSign($user_id){
|
||||
|
||||
$date = date('Y-m-d',strtotime('-1 day'));
|
||||
|
||||
$today = date('Y-m-d',time());
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'create_date' => $date,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$find = $this->dataInfo($dis);
|
||||
|
||||
if(empty($find)){
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
|
||||
$where[] = ['status','=',1];
|
||||
|
||||
$where[] = ['create_date','<>',$today];
|
||||
|
||||
$this->dataUpdate($where,['status'=>0]);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-26 14:55
|
||||
* @功能说明:发送消息
|
||||
*/
|
||||
public function sendMsg($uniacid){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$time = date('H',time());
|
||||
|
||||
if($time<10){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$push_model = new PushMsgModel($uniacid);
|
||||
|
||||
$today = strtotime(date('Y-m-d',time()));
|
||||
//开启了签到提醒
|
||||
$dis[] = ['uniacid','=',$uniacid];
|
||||
//今天没有发送过消息
|
||||
$dis[] = ['sign_notice_time','<',$today];
|
||||
//今天未签到
|
||||
$dis[] = ['sign_time','<',$today];
|
||||
|
||||
$data = $user_model->where($dis)->field('id,uniacid,id as user_id')->limit(10)->select()->toArray();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $v){
|
||||
|
||||
$res = $user_model->where(['id'=>$v['user_id']])->where('sign_notice_time','<',$today)->update(['sign_notice_time'=>time()]);
|
||||
|
||||
if($res!=0){
|
||||
|
||||
$push_model->sendMsg($v,14);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
113
app/shop/model/StoreGoods.php
Normal file
113
app/shop/model/StoreGoods.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace app\shop\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class StoreGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
//1商品 2商品分类 3土地分类 4 认养分类 5养殖管理 6秒杀
|
||||
protected $name = 'lbfarm_v2_goods_store';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-12 16:16
|
||||
* @功能说明:
|
||||
*/
|
||||
public function addData($id,$type,$uniacid,$data){
|
||||
|
||||
$this->where(['goods_id'=>$id,'type'=>$type])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'store_id' => $v,
|
||||
|
||||
'goods_id'=> $id,
|
||||
|
||||
'type' => $type
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user