初始化代码
This commit is contained in:
91
app/farm/model/AboutUs.php
Normal file
91
app/farm/model/AboutUs.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class AboutUs extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_about_us';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
91
app/farm/model/Address.php
Normal file
91
app/farm/model/Address.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Address extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_address';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
77
app/farm/model/Admin.php
Normal file
77
app/farm/model/Admin.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Admin extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_school_admin';
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
91
app/farm/model/AdminRole.php
Normal file
91
app/farm/model/AdminRole.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class AdminRole extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_admin_role';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
77
app/farm/model/Article.php
Normal file
77
app/farm/model/Article.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Article extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_article';
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
252
app/farm/model/BagAtv.php
Normal file
252
app/farm/model/BagAtv.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BagAtv extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_bag_atv';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
if(isset($data['new_coupon'])){
|
||||
|
||||
$new_coupon = $data['new_coupon'];
|
||||
|
||||
unset($data['new_coupon']);
|
||||
}
|
||||
|
||||
if(isset($data['share_coupon'])){
|
||||
|
||||
$share_coupon = $data['share_coupon'];
|
||||
|
||||
unset($data['share_coupon']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($new_coupon)&&isset($share_coupon)){
|
||||
|
||||
$this->updateSome($id,$data['uniacid'],$new_coupon,$share_coupon);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-01 14:41
|
||||
* @功能说明:添加优惠券
|
||||
*/
|
||||
public function updateSome($id,$uniacid,$new,$share){
|
||||
|
||||
$coupon_model = new BagAtvCoupon();
|
||||
|
||||
$dis = [
|
||||
|
||||
'atv_id' => $id
|
||||
];
|
||||
|
||||
$coupon_model->where($dis)->delete();
|
||||
|
||||
if(!empty($new)){
|
||||
|
||||
foreach ($new as $key=>$value){
|
||||
|
||||
$new[$key]['uniacid'] = $uniacid;
|
||||
|
||||
$new[$key]['atv_id'] = $id;
|
||||
|
||||
$new[$key]['type'] = 1;
|
||||
|
||||
}
|
||||
|
||||
$coupon_model->saveAll($new);
|
||||
}
|
||||
|
||||
if(!empty($share)){
|
||||
|
||||
foreach ($share as $k=>$v){
|
||||
|
||||
$share[$k]['uniacid'] = $uniacid;
|
||||
|
||||
$share[$k]['atv_id'] = $id;
|
||||
|
||||
$share[$k]['type'] = 2;
|
||||
|
||||
}
|
||||
|
||||
$coupon_model->saveAll($share);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(isset($data['new_coupon'])){
|
||||
|
||||
$new_coupon = $data['new_coupon'];
|
||||
|
||||
unset($data['new_coupon']);
|
||||
}
|
||||
|
||||
if(isset($data['share_coupon'])){
|
||||
|
||||
$share_coupon = $data['share_coupon'];
|
||||
|
||||
unset($data['share_coupon']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($new_coupon)&&isset($share_coupon)){
|
||||
|
||||
$this->updateSome($dis['id'],$data['uniacid'],$new_coupon,$share_coupon);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('status desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-01 18:15
|
||||
* @功能说明:检查
|
||||
*/
|
||||
public function changeData($data){
|
||||
|
||||
if(isset($data['imgs'])){
|
||||
|
||||
$data['img'] = !empty($data['imgs'])?implode(',',$data['imgs']):'';
|
||||
}
|
||||
|
||||
$id = !empty($input['id'])?$input['id']:'';
|
||||
|
||||
$where[] = ['status','>',-1];
|
||||
|
||||
$where[] = ['uniacid','=',$data['uniacid']];
|
||||
|
||||
if(!empty($id)){
|
||||
|
||||
$where[] = ['id','<>',$id];
|
||||
|
||||
}
|
||||
|
||||
$list = $this->where($where)->select()->toArray();
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$res = is_time_cross($value['start_time'],$value['end_time'],$data['start_time'],$data['end_time']);
|
||||
|
||||
if($res==false){
|
||||
|
||||
return ['code'=>500,'msg'=>'该时间段已有活动'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-03-21 15:04
|
||||
* @功能说明:正在进行的活动
|
||||
*/
|
||||
public function activeIng($uniacid,$id = ''){
|
||||
|
||||
$dis[] = ['start_time','<',time()];
|
||||
|
||||
$dis[] = ['end_time','>',time()];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
$dis[] = ['uniacid','=',$uniacid];
|
||||
|
||||
if(!empty($id)){
|
||||
|
||||
$dis[] = ['id','<>',$id];
|
||||
}
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
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-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
106
app/farm/model/BagAtvCoupon.php
Normal file
106
app/farm/model/BagAtvCoupon.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BagAtvCoupon extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_bag_atv_coupon';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-01 14:41
|
||||
* @功能说明:添加优惠券
|
||||
*/
|
||||
public function updateSome($id,$uniacid,$new,$share){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
95
app/farm/model/BagRecord.php
Normal file
95
app/farm/model/BagRecord.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BagRecord extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_bag_atv_record';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
95
app/farm/model/BagRecordCoupon.php
Normal file
95
app/farm/model/BagRecordCoupon.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BagRecordCoupon extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_bag_atv_record_coupon';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
108
app/farm/model/BalanceCard.php
Normal file
108
app/farm/model/BalanceCard.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\member\model\Level;
|
||||
use app\shop\model\Member;
|
||||
use think\facade\Db;
|
||||
|
||||
class BalanceCard extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_balance_card';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'member_title'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-09 16:29
|
||||
*/
|
||||
public function getMemberTitleAttr($value,$data){
|
||||
|
||||
if(isset($data['member_level'])){
|
||||
|
||||
$level_model = new Member();
|
||||
|
||||
$title = $level_model->where(['id'=>$data['member_level']])->value('title');
|
||||
|
||||
return !empty($title)?$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: 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('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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
230
app/farm/model/BalanceOrder.php
Normal file
230
app/farm/model/BalanceOrder.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\shop\model\IntegralLog;
|
||||
use app\member\model\Level;
|
||||
use app\member\model\Rights;
|
||||
use app\shop\model\Member;
|
||||
use longbingcore\wxcore\PospalApi;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BalanceOrder extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_balance_order_list';
|
||||
|
||||
//
|
||||
protected $append = [
|
||||
|
||||
'nick_name',
|
||||
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-11 15:47
|
||||
* @功能说明:用户昵称
|
||||
*/
|
||||
public function getNickNameAttr($value,$data){
|
||||
|
||||
if(!empty($data['user_id'])){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
return $user_model->where(['id'=>$data['user_id']])->value('nickName');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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=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: 2021-03-22 11:31
|
||||
* @功能说明:订单支付回调
|
||||
*/
|
||||
public function orderResult($order_code,$transaction_id){
|
||||
|
||||
$order = $this->dataInfo(['order_code'=>$order_code]);
|
||||
|
||||
if(!empty($order)&&$order['status']==1){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$water_model= new BalanceWater();
|
||||
|
||||
$user = $user_model->dataInfo(['id'=>$order['user_id']]);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$update = [
|
||||
|
||||
'transaction_id' => $transaction_id,
|
||||
|
||||
'status' => 2,
|
||||
|
||||
'pay_time' => time(),
|
||||
|
||||
'now_balance' => $order['true_price']+$user['balance']
|
||||
|
||||
];
|
||||
//修改订单信息
|
||||
$res = $this->dataUpdate(['id'=>$order['id']],$update);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
|
||||
$update = [
|
||||
|
||||
'balance' => $order['true_price']+$user['balance'],
|
||||
|
||||
];
|
||||
|
||||
if(!empty($order['member_level'])){
|
||||
|
||||
$update['member_level'] = $order['member_level'];
|
||||
}
|
||||
//修改用户余额
|
||||
$res = $user_model->dataUpdate(['id'=>$order['user_id']],$update);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
//添加余额流水
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'price' => $order['true_price'],
|
||||
|
||||
'order_id'=> $order['id'],
|
||||
|
||||
'add' => 1,
|
||||
|
||||
'type' => 1,
|
||||
|
||||
'before_balance' => $user['balance'],
|
||||
|
||||
'after_balance' => $order['true_price']+$user['balance'],
|
||||
];
|
||||
|
||||
$res = $water_model->dataAdd($insert);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
//增加积分
|
||||
$ilog_model = new IntegralLog();
|
||||
|
||||
$ilog_model->integralUserAdd($order['user_id'],$order['integral'],$order['uniacid'],2,2,$order['id']);
|
||||
|
||||
if(!empty($order['member_level'])){
|
||||
|
||||
$member_model = new Member();
|
||||
|
||||
$order['member_title'] = $member_model->where(['id'=>$order['member_level']])->value('title');
|
||||
|
||||
$push_model = new PushMsgModel($order['uniacid']);
|
||||
|
||||
$push_model->sendMsg($order,16);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
386
app/farm/model/BalanceWater.php
Normal file
386
app/farm/model/BalanceWater.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BalanceWater extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_balance_water';
|
||||
|
||||
//
|
||||
protected $append = [
|
||||
|
||||
'goods_title',
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-07 17:44
|
||||
* @功能说明:项目名称
|
||||
*/
|
||||
public function getGoodsTitleAttr($value,$data){
|
||||
|
||||
if(!empty($data['type'])&&!empty($data['order_id'])&&isset($data['add'])){
|
||||
|
||||
$title = '';
|
||||
|
||||
$balance_order_model = new BalanceOrder();
|
||||
//充值
|
||||
if($data['type']==1){
|
||||
|
||||
$title = $balance_order_model->where(['id'=>$data['order_id']])->value('title');
|
||||
//认养
|
||||
}elseif($data['type']==2){
|
||||
|
||||
$order_model = new ClaimOrder();
|
||||
|
||||
$title = $order_model->where(['id'=>$data['order_id']])->value('goods_name');
|
||||
|
||||
//养殖订单
|
||||
}elseif($data['type']==5){
|
||||
|
||||
$shop_order_model = new BreedOrderGoods();
|
||||
|
||||
$title = $shop_order_model->where(['order_id'=>$data['order_id']])->column('goods_name');
|
||||
|
||||
$title = !empty($title)?implode(',',$title):'';
|
||||
//土地订单
|
||||
}elseif($data['type']==4){
|
||||
|
||||
$order_model = new LandOrder();
|
||||
|
||||
$title = $order_model->where(['id'=>$data['order_id']])->value('spe_name');
|
||||
|
||||
}elseif($data['type']==7||$data['type']==11){
|
||||
|
||||
$order_model = new ShopOrderGoods();
|
||||
|
||||
$title = $order_model->where(['order_id'=>$data['order_id']])->column('goods_name');
|
||||
|
||||
$title = !empty($title)?implode(',',$title):'';
|
||||
}
|
||||
|
||||
return $title;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-05 09:56
|
||||
* @功能说明:
|
||||
*/
|
||||
public function sceneText($type){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
|
||||
$text = '购买储值卡';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
$text = '认养订单';
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$text = '认养配送订单';
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
||||
$text = '配送订单退款';
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
|
||||
$text = '养殖订单';
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
|
||||
$text = '土地订单';
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
|
||||
$text = '商城交易支付';
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
|
||||
$text = '提现';
|
||||
|
||||
break;
|
||||
case 9:
|
||||
|
||||
$text = '土地配送订单';
|
||||
|
||||
break;
|
||||
case 10:
|
||||
|
||||
$text = '商城订单退款';
|
||||
|
||||
break;
|
||||
case 11:
|
||||
|
||||
$text = '商城交易收入';
|
||||
|
||||
break;
|
||||
|
||||
case 12:
|
||||
|
||||
$text = '拒绝提现';
|
||||
|
||||
break;
|
||||
|
||||
case 13:
|
||||
|
||||
$text = '认养订单';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$text = '购买储值卡1';
|
||||
|
||||
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();
|
||||
|
||||
// if(){
|
||||
//
|
||||
// }
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function indexList($dis,$page=10){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['after_balance'] = round($v['after_balance'],2);
|
||||
|
||||
$v['before_balance'] = round($v['before_balance'],2);
|
||||
|
||||
$add_text = $v['add']==1?'+':'-';
|
||||
|
||||
$buy_text = $v['add']==1?'退款':'消费';
|
||||
|
||||
if($v['type']==1){
|
||||
|
||||
$buy_text = '';
|
||||
}
|
||||
|
||||
$scene_text = $this->sceneText($v['type']);
|
||||
|
||||
$v['text'] = $scene_text.$buy_text.'【'.$v['goods_title'].'】'.$add_text.'¥'.$v['price'].'现余额¥'.$v['after_balance'];
|
||||
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-09 11:14
|
||||
* @功能说明:增加流水并且修改用户余额
|
||||
*/
|
||||
public function addWater($order,$type,$add=0){
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$water_model = new BalanceWater();
|
||||
|
||||
$user = $user_model->dataInfo(['id'=>$order['user_id']]);
|
||||
//如果是平台
|
||||
if(empty($user)){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $user['id'],
|
||||
|
||||
'lock' => $user['lock']
|
||||
|
||||
];
|
||||
|
||||
$update = [
|
||||
|
||||
'lock' => $user['lock']+1
|
||||
];
|
||||
|
||||
if($add==0){
|
||||
|
||||
$update['balance'] = $user['balance']-$order['pay_price'];
|
||||
//地主提现或者退款
|
||||
if(in_array($type,[8,10])){
|
||||
|
||||
$update['wallet_cash'] = $user['wallet_cash'] - $order['pay_price'];
|
||||
|
||||
$update['landlord_cash'] = $user['landlord_cash']- $order['pay_price'];
|
||||
}
|
||||
//如果总余额小于可提现余额 可提现余额也要减掉
|
||||
if($update['balance']<$user['wallet_cash']){
|
||||
|
||||
$update['wallet_cash'] = $update['balance'];
|
||||
|
||||
$update['landlord_cash'] = $update['balance'];
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$update['balance'] = $user['balance']+$order['pay_price'];
|
||||
//地主收入 需要增加可提现余额
|
||||
if($type==11||$type==12){
|
||||
|
||||
$update['wallet_cash'] = $user['wallet_cash']+$order['pay_price'];
|
||||
|
||||
$update['landlord_cash'] = $user['landlord_cash']+$order['pay_price'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//修改用户余额
|
||||
$res = $user_model->dataUpdate($dis,$update);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
}
|
||||
//添加余额流水
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'price' => $order['pay_price'],
|
||||
|
||||
'order_id'=> $order['id'],
|
||||
|
||||
'add' => $add,
|
||||
|
||||
'type' => $type,
|
||||
|
||||
'before_balance' => $user['balance'],
|
||||
|
||||
'after_balance' => $add==0?$user['balance']-$order['pay_price']:$user['balance']+$order['pay_price'],
|
||||
];
|
||||
|
||||
$res = $water_model->dataAdd($insert);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
117
app/farm/model/Banner.php
Normal file
117
app/farm/model/Banner.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Banner extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_banner';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-11-09 13:37
|
||||
* @功能说明:详情
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-15 11:12
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function updateSome($id,$data){
|
||||
|
||||
if(empty($data['type'])){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$text_model = new BannerText();
|
||||
|
||||
$text_model->where(['banner_id'=>$id,'type'=>$data['type']])->delete();
|
||||
|
||||
if(!empty($data['text_id'])){
|
||||
|
||||
foreach ($data['text_id'] as $k=>$v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'text_id' => $v,
|
||||
|
||||
'banner_id'=> $id,
|
||||
|
||||
'type' => $data['type']
|
||||
];
|
||||
}
|
||||
|
||||
$text_model->saveAll($insert);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
76
app/farm/model/BannerText.php
Normal file
76
app/farm/model/BannerText.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BannerText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_banner_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: 2021-11-09 13:37
|
||||
* @功能说明:详情
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
265
app/farm/model/Breed.php
Normal file
265
app/farm/model/Breed.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\shop\model\StoreGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class Breed extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_breed';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-04 17:23
|
||||
*/
|
||||
public function getFarmerIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.status' => 2,
|
||||
|
||||
'a.goods_id' => $data['id'],
|
||||
|
||||
'a.type' => 5
|
||||
];
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:养殖列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-12 17:57
|
||||
*/
|
||||
public function breedList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_store b','a.id = b.goods_id','left')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->order('a.top desc,a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(!empty($data['farmer_id'])){
|
||||
|
||||
$farmer = $data['farmer_id'];
|
||||
|
||||
unset($data['farmer_id']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
if(isset($farmer)){
|
||||
|
||||
$res = $this->getLastInsID();
|
||||
|
||||
$this->updateSome($res,$farmer,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(!empty($data['farmer_id'])){
|
||||
|
||||
$farmer = $data['farmer_id'];
|
||||
|
||||
unset($data['farmer_id']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($farmer)){
|
||||
|
||||
$this->updateSome($dis['id'],$farmer,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @param $uniacid
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-12 17:17
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$store_goods_model = new StoreGoods();
|
||||
|
||||
$res = $store_goods_model->addData($id,5,$uniacid,$data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page=10){
|
||||
|
||||
$data = $this->where($dis)->order('status desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-09 16:11
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function indexDataList($dis,$page=10){
|
||||
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_store b','a.id = b.goods_id')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->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-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-29 17:05
|
||||
* @功能说明:获取养殖购物车信息
|
||||
*/
|
||||
public function getCarList($user_id,$farmer_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.user_id' => $user_id,
|
||||
|
||||
'b.farmer_id'=> $farmer_id,
|
||||
|
||||
'a.status' => 1,
|
||||
|
||||
'b.type' => 1,
|
||||
|
||||
'c.type' => 5,
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_car b','a.id = b.goods_id')
|
||||
->join('lbfarm_v2_goods_store c','a.id = c.goods_id')
|
||||
->where($dis)
|
||||
->field('a.*,b.goods_num,b.goods_id,ROUND(a.price*b.goods_num,2) as all_price')
|
||||
->group('b.id')
|
||||
->order('b.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$arr['car_list'] = $data;
|
||||
|
||||
$arr['price'] = array_sum(array_column($data,'all_price'));
|
||||
|
||||
$arr['goods_num']= array_sum(array_column($data,'goods_num'));
|
||||
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
172
app/farm/model/BreedOrder.php
Normal file
172
app/farm/model/BreedOrder.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\BalanceWater;
|
||||
use app\farm\model\User;
|
||||
use app\shop\model\IntegralLog;
|
||||
use think\facade\Db;
|
||||
|
||||
class BreedOrder extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_breed_order';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'order_goods'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-10 16:04
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getOrderGoodsAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$order_goods_model = new BreedOrderGoods();
|
||||
|
||||
$list = $order_goods_model->where(['order_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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-16 15:39
|
||||
* @功能说明:回调
|
||||
*/
|
||||
public function orderResult($order_code,$transaction_id){
|
||||
|
||||
$order = $this->dataInfo(['order_code'=>$order_code]);
|
||||
|
||||
if(!empty($order)&&$order['pay_type']==1){
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_time' => time(),
|
||||
|
||||
'pay_type' => 7,
|
||||
|
||||
'transaction_id' => $transaction_id
|
||||
];
|
||||
|
||||
$this->dataUpdate(['id'=>$order['id']],$update);
|
||||
//扣除余额
|
||||
if($order['balance']>0){
|
||||
|
||||
$water_model = new BalanceWater();
|
||||
|
||||
$res = $water_model->addWater($order,5,0);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
}
|
||||
//添加流水
|
||||
$water_model = new FinanceWater();
|
||||
|
||||
$water_model->addWater($order['id'],6,1,1);
|
||||
|
||||
$integral_model = new IntegralLog();
|
||||
|
||||
$integral_model->integralUserAdd($order['user_id'],$order['get_integral'],$order['uniacid'],2,7,$order['id']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
128
app/farm/model/BreedOrderGoods.php
Normal file
128
app/farm/model/BreedOrderGoods.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class BreedOrderGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_breed_order_goods';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-29 17:19
|
||||
* @功能说明:
|
||||
*/
|
||||
public function orderAdd($goods,$order_id){
|
||||
|
||||
foreach ($goods as $v){
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $v['uniacid'],
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'goods_id' => $v['goods_id'],
|
||||
|
||||
'goods_name' => $v['title'],
|
||||
|
||||
'goods_cover' => $v['cover'],
|
||||
|
||||
'goods_num' => $v['goods_num'],
|
||||
|
||||
'true_num' => $v['goods_num'],
|
||||
|
||||
'goods_price' => $v['price'],
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
371
app/farm/model/Car.php
Normal file
371
app/farm/model/Car.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\shop\model\IntegralList;
|
||||
use app\shop\model\SeckillList;
|
||||
use think\facade\Db;
|
||||
|
||||
class Car extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_car';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-10 15:19
|
||||
* @功能说明:获取购物车内的价格
|
||||
*/
|
||||
public function carBreedPrice($user_id,$farmer_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.user_id' => $user_id,
|
||||
|
||||
'a.farmer_id' => $farmer_id,
|
||||
|
||||
'a.type' => 1,
|
||||
|
||||
'a.status' => 1
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_breed b','a.goods_id = b.id')
|
||||
->where($dis)
|
||||
->field('(a.goods_num*b.price) as total_price')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return array_sum(array_column($data,'total_price'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 17:21
|
||||
* @功能说明:购物车价格
|
||||
*/
|
||||
public function carPriceAndCount($user_id,$store_id,$is_car=0,$is_show=1,$no_i=1){
|
||||
//查询积分活动
|
||||
$integral_model = new IntegralList();
|
||||
|
||||
$kill_model = new SeckillList();
|
||||
//选中
|
||||
$list = $this->carList($user_id,$store_id,0,$is_show);
|
||||
//所有 is_car0的时候也是选中
|
||||
$data['list'] = $this->carList($user_id,$store_id,$is_car,$is_show);
|
||||
//是否是秒杀商品
|
||||
$have_kill = $kill_model->getBuyLimit($data['list']);
|
||||
|
||||
if(!empty($have_kill)){
|
||||
|
||||
$buy_limit = 0;
|
||||
|
||||
$no_i = 1;
|
||||
|
||||
$discount_add = 0;
|
||||
|
||||
}else{
|
||||
$min = $integral_model->getBuyLimit($data['list']);
|
||||
//获取是否允许原价购买 1允许 0不允许
|
||||
$buy_limit = $min['buy_limit'];
|
||||
|
||||
$no_i = $buy_limit==1?$no_i:0;
|
||||
//是否允许优惠活动叠加
|
||||
$discount_add = $no_i==0?$min['discount_add']:1;
|
||||
|
||||
}
|
||||
//积分抵扣掉的钱
|
||||
$integral_discount_price = $kill_discount_price = 0;
|
||||
//积分
|
||||
$integral = 0;
|
||||
|
||||
if(!empty($data['list'])){
|
||||
|
||||
foreach ($data['list'] as &$vs){
|
||||
|
||||
$vs['member_discount'] = 100;
|
||||
|
||||
$vs['integral'] = $vs['i_price'] = $vs['integral_id'] = $vs['kill_atv_id'] = $v['integral_discount_price'] = 0;
|
||||
|
||||
$kill_list = $kill_model->atvIng($vs['goods_id'],$vs['spe_id']);
|
||||
//秒杀
|
||||
if(!empty($kill_list)){
|
||||
|
||||
$vs['true_price'] = $kill_list['price']*$vs['goods_num'];
|
||||
|
||||
$vs['kill_atv_id'] = $kill_list['id'];
|
||||
|
||||
$kill_discount_price = $vs['kill_discount_price'] = $vs['all_price'] - $vs['true_price'];
|
||||
|
||||
}else{
|
||||
//查询正在进行中的积分活动
|
||||
$info = $integral_model->atvIng($vs['goods_id'],$vs['spe_id']);
|
||||
|
||||
if(!empty($info)){
|
||||
//使用积分抵扣掉的钱
|
||||
$integral_discount_price += $vs['all_price'] - $info['price']*$vs['goods_num'];
|
||||
//使用积分
|
||||
$integral += $info['integral']*$vs['goods_num'];
|
||||
//使用积分抵扣
|
||||
if($buy_limit==0||$no_i==0){
|
||||
|
||||
$vs['true_price'] = $info['price']*$vs['goods_num'];
|
||||
|
||||
$vs['integral_id'] = $info['atv_id'];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$vs['kill_price'] = !empty($kill_list)?$kill_list['price']:0;
|
||||
|
||||
$vs['kill_end_time'] = !empty($kill_list)?$kill_list['end_time']:0;
|
||||
|
||||
$vs['integral'] = !empty($info['integral'])?$info['integral']:0;
|
||||
|
||||
$vs['i_price'] = !empty($info['price'])?$info['price']:0;
|
||||
|
||||
$vs['total_integral_discount_price'] = !empty($info['price'])?$vs['all_price'] - $info['price']*$vs['goods_num']:0;
|
||||
|
||||
$vs['total_integral'] = !empty($info['integral'])?$info['integral']*$vs['goods_num']:0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//总的数量
|
||||
$data['all_count'] = array_sum(array_column($data['list'],'goods_num'));
|
||||
|
||||
if($is_car==0){
|
||||
|
||||
$list = $data['list'];
|
||||
}
|
||||
//拼接订单
|
||||
$data['list'] = $this->getFarmerCar($data['list']);
|
||||
|
||||
$data['kill_atv_id'] = !empty($kill_list)?$kill_list['id']:0;
|
||||
|
||||
$data['kill_over_time'] = !empty($kill_list)?$kill_list['over_time']:0;
|
||||
//积分抵扣
|
||||
$data['integral'] = $integral;
|
||||
//积分抵扣多少钱
|
||||
$data['integral_discount_price'] = round($integral_discount_price,2);
|
||||
//
|
||||
$data['kill_discount_price'] = round($kill_discount_price,2);
|
||||
|
||||
$data['buy_limit'] = $buy_limit;
|
||||
|
||||
$data['discount_add'] = $discount_add;
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
$data['car_price'] = round(array_sum(array_column($list,'true_price')),2);
|
||||
//原价
|
||||
$data['init_price'] = round(array_sum(array_column($list,'all_price')),2);;
|
||||
//选中的数量
|
||||
$data['car_count'] = array_sum(array_column($list,'goods_num'));
|
||||
|
||||
}else{
|
||||
|
||||
$data['init_price'] = 0;
|
||||
|
||||
$data['car_price'] = 0;
|
||||
|
||||
$data['car_count'] = 0;
|
||||
|
||||
$data['all_count'] = 0;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-23 11:26
|
||||
* @功能说明:转换成农场格式
|
||||
*/
|
||||
public function getFarmerCar($car){
|
||||
|
||||
$farmer_model = new Farmer();
|
||||
|
||||
$arr = [];
|
||||
|
||||
foreach ($car as $value){
|
||||
|
||||
$arr[$value['farmer_id']]['goods_list'][] = $value;
|
||||
|
||||
$arr[$value['farmer_id']]['farmer_id'] = $value['farmer_id'];
|
||||
|
||||
}
|
||||
|
||||
foreach ($arr as &$vs){
|
||||
|
||||
$vs['farmer_info']= $farmer_model->dataInfo(['id'=>$vs['farmer_id']],'title,lng,lat,uniacid');
|
||||
|
||||
$vs['car_price'] = round(array_sum(array_column($vs['goods_list'],'true_price')),2);
|
||||
//原价
|
||||
$vs['init_price'] = round(array_sum(array_column($vs['goods_list'],'all_price')),2);
|
||||
|
||||
$vs['integral'] = round(array_sum(array_column($vs['goods_list'],'total_integral')),2);
|
||||
|
||||
$vs['integral_discount_price'] = round(array_sum(array_column($vs['goods_list'],'total_integral_discount_price')),2);
|
||||
|
||||
$vs['kill_discount_price'] = round(array_sum(array_column($vs['goods_list'],'kill_discount_price')),2);
|
||||
//运费
|
||||
$vs['freight'] = 0;
|
||||
|
||||
$vs['coupon_discount'] = 0;
|
||||
|
||||
}
|
||||
|
||||
return array_values($arr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 17:35
|
||||
* @功能说明:购物车列表
|
||||
*/
|
||||
public function carList($user_id,$store_id=0,$all=0,$is_show=1){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.user_id' => $user_id,
|
||||
|
||||
'b.status' => 1,
|
||||
|
||||
'a.type' => 5,
|
||||
|
||||
'a.is_show' => $is_show,
|
||||
|
||||
'e.status' => 2
|
||||
];
|
||||
|
||||
if($all==0){
|
||||
|
||||
$dis['a.status'] = 1;
|
||||
}
|
||||
|
||||
if(!empty($store_id)){
|
||||
|
||||
$dis['d.store_id']= $store_id;
|
||||
}
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_shop_goods b','a.goods_id = b.id')
|
||||
->join('lbfarm_v2_shop_spe_price c','a.spe_id = c.id','left')
|
||||
->join('lbfarm_v2_goods_store d','a.goods_id = d.goods_id AND d.type=1')
|
||||
->join('lbfarm_farmer e','d.store_id = e.id')
|
||||
->where($dis)
|
||||
->field('a.id,c.spe_id_1,b.send_tmpl_id,b.sale_num,b.true_sale_num,e.id as farmer_id,a.status,a.uniacid,a.goods_num,b.goods_name,b.cover,c.price,ROUND(c.price*a.goods_num,2) as all_price,ROUND(c.price*a.goods_num,2) as true_price,a.spe_id,a.goods_id,b.weight*a.goods_num as total_weight')
|
||||
->group('a.id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as &$v){
|
||||
|
||||
$v['all_sale_num'] = $v['sale_num']+$v['true_sale_num'];
|
||||
|
||||
$pec_id = explode('-',$v['spe_id_1']);
|
||||
|
||||
$spe_name = Db::name('lbfarm_v2_shop_spe')->where(['status'=>1])->where('id','IN',$pec_id)->column('title');
|
||||
|
||||
$v['spe_name'] = implode('-',$spe_name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
330
app/farm/model/Claim.php
Normal file
330
app/farm/model/Claim.php
Normal file
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Claim extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_claim';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-12 16:10
|
||||
*/
|
||||
public function getCateIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.status' => 1,
|
||||
|
||||
'a.goods_id' => $data['id'],
|
||||
|
||||
'a.type' => 3,
|
||||
|
||||
'b.type' => 2,
|
||||
];
|
||||
|
||||
$goods_cate_model = new GoodsCate();
|
||||
|
||||
$list = $goods_cate_model->alias('a')
|
||||
->join('lbfarm_land_cate b','a.cate_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.title')
|
||||
->group('a.id')
|
||||
->order('a.id dsec')
|
||||
->column('b.id');
|
||||
|
||||
|
||||
return array_values($list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-26 15:16
|
||||
*/
|
||||
public function getTextAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return @unserialize($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-07 10:50
|
||||
* @功能说明:轮播图转格式
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-06 15:24
|
||||
* @功能说明:周期
|
||||
*/
|
||||
public function getCycleAttr($value,$data){
|
||||
|
||||
if(isset($data['start_time'])&&isset($data['end_time'])){
|
||||
|
||||
$day = ceil(($data['end_time']-$data['start_time'])/86400);
|
||||
|
||||
return $day;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$g_data = $data;
|
||||
|
||||
if(isset($data['process'])){
|
||||
|
||||
unset($data['process']);
|
||||
}
|
||||
|
||||
if(isset($data['monitor'])){
|
||||
|
||||
unset($data['monitor']);
|
||||
}
|
||||
|
||||
if(isset($data['cate_id'])){
|
||||
|
||||
unset($data['cate_id']);
|
||||
}
|
||||
|
||||
if(!empty($data['imgs'])){
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
}
|
||||
|
||||
if(!empty($data['text'])){
|
||||
|
||||
$data['text'] = serialize($data['text']);
|
||||
}
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$this->updateSome($id,$g_data);
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$g_data = $data;
|
||||
|
||||
if(isset($data['process'])){
|
||||
|
||||
unset($data['process']);
|
||||
}
|
||||
|
||||
if(isset($data['monitor'])){
|
||||
|
||||
unset($data['monitor']);
|
||||
}
|
||||
|
||||
if(isset($data['cate_id'])){
|
||||
|
||||
unset($data['cate_id']);
|
||||
}
|
||||
|
||||
if(!empty($data['imgs'])){
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
}
|
||||
|
||||
if(!empty($data['text'])){
|
||||
|
||||
$data['text'] = serialize($data['text']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($g_data['process'])||isset($g_data['monitor'])){
|
||||
|
||||
$this->updateSome($dis['id'],$g_data);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-14 15:45
|
||||
* @功能说明:添加关联
|
||||
*/
|
||||
public function updateSome($id,$data){
|
||||
|
||||
$server = new \app\farm\server\Claim();
|
||||
|
||||
$claim_text_model = new ClaimText();
|
||||
|
||||
$monitor_text_model= new MonitorText();
|
||||
|
||||
$goods_cate_model = new GoodsCate();
|
||||
|
||||
$server->addObserver($goods_cate_model);
|
||||
|
||||
$server->addObserver($claim_text_model);
|
||||
|
||||
$server->addObserver($monitor_text_model);
|
||||
|
||||
$server->notify($id,$data);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page=10){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function indexDataList($dis,$alh,$sort=1){
|
||||
|
||||
switch ($sort){
|
||||
|
||||
case 1:
|
||||
$order = 'id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$order = 'sale_num desc,id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$order = 'distance asc,id desc';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$data = $this->where($dis)->field(['*',$alh])->order($order)->paginate(10)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-20 14:00
|
||||
* @功能说明:前端土地列表
|
||||
*/
|
||||
public function indexDataListV2($dis,$alh,$sort=1){
|
||||
|
||||
switch ($sort){
|
||||
|
||||
case 1:
|
||||
$order = 'a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$order = 'a.sale_num desc,a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$order = 'a.distance asc,a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_cate b','a.id = b.goods_id','left')
|
||||
->where($dis)
|
||||
->field(['a.*',$alh])
|
||||
->group('a.id')
|
||||
->order($order)
|
||||
->paginate(10)
|
||||
->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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
142
app/farm/model/ClaimCollage.php
Normal file
142
app/farm/model/ClaimCollage.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ClaimCollage extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_claim_collage_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('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-01 15:33
|
||||
* @功能说明:
|
||||
*/
|
||||
public function adminDataList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim b','a.claim_id = b.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title as claim_title,b.price as init_price,b.cover as claim_cover')
|
||||
->group('a.id')
|
||||
->order('a.top desc,a.id')
|
||||
->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-08-18 10:33
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getAtvInfo($atv_id,$claim_id){
|
||||
|
||||
$data = $this->dataInfo(['id'=>$atv_id,'claim_id'=>$claim_id]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 11:16
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getAtvInfoIng($claim_id,$user_id=0){
|
||||
|
||||
$dis[] = ['claim_id','=',$claim_id];
|
||||
|
||||
$dis[] = ['start_time','<',time()];
|
||||
|
||||
$dis[] = ['end_time','>',time()];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
$data = $this->dataInfo($dis);
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$collage_model = new CollageStart();
|
||||
|
||||
$data['can_start'] = $collage_model->startAtvCheck($user_id,$data['id']);
|
||||
//是否还能发起该活动其他的拼团
|
||||
$data['can_start'] = !empty($data['can_start']['code'])?0:1;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
533
app/farm/model/ClaimOrder.php
Normal file
533
app/farm/model/ClaimOrder.php
Normal file
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\BalanceWater;
|
||||
use app\farm\model\User;
|
||||
use app\publics\model\TmplConfig;
|
||||
use app\shop\model\DistributionCash;
|
||||
use app\shop\model\IntegralLog;
|
||||
use longbingcore\wxcore\PayModel;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ClaimOrder extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_claim_order';
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-14 15:45
|
||||
* @功能说明:添加关联
|
||||
*/
|
||||
public function updateSome($id,$data){
|
||||
|
||||
$server = new \app\farm\server\Claim();
|
||||
|
||||
$claim_text_model = new ClaimText();
|
||||
|
||||
$source_text_model= new LandSourceText();
|
||||
|
||||
$monitor_text_model= new MonitorText();
|
||||
|
||||
$server->addObserver($claim_text_model);
|
||||
|
||||
$server->addObserver($source_text_model);
|
||||
|
||||
$server->addObserver($monitor_text_model);
|
||||
|
||||
$server->notify($id,$data);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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: 2021-12-16 15:39
|
||||
* @功能说明:回调
|
||||
*/
|
||||
public function orderResult($order_code,$transaction_id){
|
||||
|
||||
$order = $this->dataInfo(['order_code'=>$order_code]);
|
||||
|
||||
if(!empty($order)&&$order['pay_type']==1){
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_time' => time(),
|
||||
|
||||
'pay_type' => 2,
|
||||
|
||||
'transaction_id' => $transaction_id
|
||||
];
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$this->dataUpdate(['id'=>$order['id']],$update);
|
||||
//扣除余额
|
||||
if($order['balance']>0){
|
||||
|
||||
$water_model = new BalanceWater();
|
||||
|
||||
$res = $water_model->addWater($order,2,0);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
}
|
||||
//添加流水
|
||||
$water_model = new FinanceWater();
|
||||
|
||||
$water_model->addWater($order['id'],1,1,1);
|
||||
|
||||
$integral_model = new IntegralLog();
|
||||
//增加佣金
|
||||
$integral_model->integralUserAdd($order['user_id'],$order['get_integral'],$order['uniacid'],2,5,$order['id'],0,$order);
|
||||
//分销
|
||||
$cash_model = new DistributionCash();
|
||||
//增加分销激励
|
||||
$cash_model->addUserCash($order,3);
|
||||
//分销到账
|
||||
$cash_model->cashArrival($order,3);
|
||||
|
||||
$collage_model = new CollageStart();
|
||||
//拼团
|
||||
$collage_model->atvResult($order['id']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
$sys_model = new PushMsgModel($order['uniacid']);
|
||||
|
||||
$sys_model->sendMsg($order,8);
|
||||
|
||||
$sys_model->sendMsg($order,10);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 10:13
|
||||
* @功能说明:超时自动退款
|
||||
*/
|
||||
public function autoCancelOrder($uniacid,$user_id=0){
|
||||
|
||||
$dis[] = ['uniacid','=',$uniacid];
|
||||
|
||||
$dis[] = ['pay_type','=',1];
|
||||
|
||||
$dis[] = ['over_time','<',time()];
|
||||
|
||||
if(!empty($user_id)){
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
}
|
||||
|
||||
$order = $this->where($dis)->select()->toArray();
|
||||
|
||||
if(!empty($order)){
|
||||
|
||||
foreach ($order as $value){
|
||||
|
||||
$this->cancelOrder($value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 10:13
|
||||
* @功能说明:退款
|
||||
*/
|
||||
public function cancelOrder($order,$refund =1,$payConfig=[]){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
if($refund==2){
|
||||
|
||||
$res = $this->refundCash($payConfig,$order);
|
||||
|
||||
if($res!=true){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败'];
|
||||
}
|
||||
|
||||
}else{
|
||||
//取消订单
|
||||
$collage_model = new CollageStart();
|
||||
|
||||
$collage_model->cancelOrderAtvFail($order['id']);
|
||||
|
||||
}
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$order['id'],'pay_type'=>$refund],['pay_type'=>-1,'cancel_time'=>time()]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'取消失败'];
|
||||
}
|
||||
|
||||
$claim_model = new Claim();
|
||||
|
||||
$claim = $claim_model->dataInfo(['id'=>$order['goods_id']]);
|
||||
//加销量减库存
|
||||
$update = [
|
||||
|
||||
'stock' => $claim['stock'] +$order['num'],
|
||||
|
||||
'sale_num' => $claim['sale_num']-$order['num'],
|
||||
|
||||
'lock' => $claim['lock']+1
|
||||
|
||||
];
|
||||
|
||||
$res = $claim_model->dataUpdate(['id'=>$claim['id'],'lock'=>$claim['lock']],$update);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'取消失败'];
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 13:53
|
||||
* @功能说明:退钱
|
||||
*/
|
||||
public function refundCash($payConfig,$pay_order){
|
||||
|
||||
if($pay_order['pay_price']<=0){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$water_model = new FinanceWater();
|
||||
|
||||
$water_model->addWater($pay_order['id'],2,1,1);
|
||||
|
||||
if($pay_order['pay_model']==1){
|
||||
//微信退款
|
||||
$response = orderRefundApi($payConfig,$pay_order['pay_price'],$pay_order['pay_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'=>$pay_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];
|
||||
|
||||
}
|
||||
|
||||
}elseif($pay_order['pay_model']==2){
|
||||
|
||||
$data = [
|
||||
|
||||
'user_id' => $pay_order['user_id'],
|
||||
|
||||
'pay_price'=> $pay_order['pay_price'],
|
||||
|
||||
'id' => $pay_order['id'],
|
||||
|
||||
'uniacid' => $pay_order['uniacid']
|
||||
];
|
||||
|
||||
$water_model = new \app\farm\model\BalanceWater();
|
||||
|
||||
$res = $water_model->addWater($data,13,1);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
//支付宝
|
||||
$pay_model = new PayModel($payConfig);
|
||||
|
||||
$res = $pay_model->aliRefund($pay_order['transaction_id'],$pay_order['pay_price']);
|
||||
|
||||
if(isset($res['alipay_trade_refund_response']['code'])&&$res['alipay_trade_refund_response']['code']==10000){
|
||||
|
||||
$this->dataUpdate(['id'=>$pay_order['id']],['out_refund_no'=>$res['alipay_trade_refund_response']['out_trade_no']]);
|
||||
|
||||
}else{
|
||||
|
||||
return ['code'=>500,'msg'=> $res['alipay_trade_refund_response']['sub_msg']];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:后台下单列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 14:05
|
||||
*/
|
||||
public function adminDataList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_order_address b','a.id = b.order_id AND b.type=2','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.user_name,b.mobile')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:后台下单列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 14:05
|
||||
*/
|
||||
public function adminDataSelect($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_order_address b','a.id = b.order_id AND b.type=2','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.user_name,b.mobile')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-24 16:46
|
||||
* @功能说明:预支付信息
|
||||
*/
|
||||
public function payOrderInfo($input,$is_err=0){
|
||||
|
||||
$claim_model = new Claim();
|
||||
|
||||
$data = $claim_model->dataInfo(['id'=>$input['claim_id'],'status'=>1]);
|
||||
|
||||
$input['num'] = !empty($input['num'])?$input['num']:1;
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
return ['code'=>500,'msg'=>'该产品已下架'];
|
||||
}
|
||||
|
||||
if($data['stock']<$input['num']&&$is_err==1){
|
||||
|
||||
return ['code'=>500,'msg'=>'该产品库存不足'];
|
||||
}
|
||||
|
||||
if($data['end_time']<time()&&$is_err==1){
|
||||
|
||||
return ['code'=>500,'msg'=>'该产品认养期已结束'];
|
||||
|
||||
}
|
||||
|
||||
$data['pay_price'] = round($data['price']*$input['num'],2);
|
||||
|
||||
$pay_price = $data['init_price'] = $data['pay_price'];
|
||||
|
||||
if(!empty($input['coupon_id'])&&empty($input['collage_start_id'])){
|
||||
|
||||
$coupon_record_model = new CouponRecord();
|
||||
|
||||
$coupon = $coupon_record_model->dataInfo(['id'=>$input['coupon_id'],'is_claim'=>1,'status'=>1]);
|
||||
|
||||
if(!empty($coupon)&&$coupon['full']<=$data['pay_price']){
|
||||
|
||||
$data['pay_price'] -= $coupon['discount'];
|
||||
|
||||
}else{
|
||||
|
||||
$coupon = [];
|
||||
}
|
||||
|
||||
}
|
||||
//发起拼团
|
||||
if(!empty($input['collage_start_id'])){
|
||||
|
||||
$collage_model = new ClaimCollage();
|
||||
|
||||
$data['collage_start_data'] = $collage_model->getAtvInfo($input['collage_start_id'],$input['claim_id']);
|
||||
|
||||
if(!empty($data['collage_start_data'])){
|
||||
|
||||
$data['pay_price'] = $data['collage_start_data']['price'];
|
||||
}
|
||||
//参与拼团
|
||||
}elseif(!empty($input['collage_join_id'])){
|
||||
|
||||
$collage_model = new CollageStart();
|
||||
|
||||
$data['collage_join_data'] = $collage_model->getAtvInfo($input['collage_join_id'],$input['claim_id']);
|
||||
|
||||
if(!empty($data['collage_join_data'])){
|
||||
|
||||
$data['pay_price'] = $data['collage_join_data']['price'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data['pay_price'] = $data['pay_price']>0?$data['pay_price']:0;
|
||||
|
||||
$data['pay_price'] = round($data['pay_price'],2);
|
||||
|
||||
$data['coupon_discount'] = !empty($coupon)?$coupon['discount']:0;
|
||||
|
||||
$data['coupon_discount'] = $data['coupon_discount']<$pay_price?$data['coupon_discount']:$pay_price;
|
||||
|
||||
$data['coupon_discount'] = round($data['coupon_discount'],2);
|
||||
|
||||
$data['coupon_id'] = !empty($coupon)?$coupon['id']:0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-09 17:45
|
||||
* @功能说明:认养发送可配送提醒
|
||||
*/
|
||||
public function claimSendNotice($uniacid){
|
||||
|
||||
$push_model = new PushMsgModel($uniacid);
|
||||
|
||||
$dis[] = ['pay_type','>',1];
|
||||
|
||||
$dis[] = ['have_notice','=',0];
|
||||
|
||||
$dis[] = ['end_time','<',time()];
|
||||
|
||||
$list = $this->where($dis)->select()->toArray();
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$this->dataUpdate(['id'=>$value['id']],['have_notice'=>1]);
|
||||
|
||||
$push_model->sendMsg($value,7);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
103
app/farm/model/ClaimText.php
Normal file
103
app/farm/model/ClaimText.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ClaimText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_claim_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-12-14 16:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventClaim($id,$data){
|
||||
|
||||
$this->where(['claim_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data['process'])){
|
||||
|
||||
foreach ($data['process'] as $k => $v){
|
||||
|
||||
$v['uniacid'] = $data['uniacid'];
|
||||
|
||||
$v['claim_id']= $id;
|
||||
|
||||
$this->insert($v);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
354
app/farm/model/CollageJoin.php
Normal file
354
app/farm/model/CollageJoin.php
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class CollageJoin extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_claim_collage_join';
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2022-07-01 15:33
|
||||
* @功能说明:
|
||||
*/
|
||||
public function adminDataList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim b','a.claim_id = b.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title as claim_title')
|
||||
->group('a.id')
|
||||
->order('a.top desc,a.id')
|
||||
->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-08-16 15:25
|
||||
* @功能说明:用户拼团记录
|
||||
*/
|
||||
public function userCollageLimit($dis,$limit=3){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim b','a.claim_id = b.id','left')
|
||||
->join('lbfarm_v2_claim_collage_start c','a.start_id = c.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title as claim_title,b.cover as claim_cover,c.end_time,c.success_num,c.have_order_num as have_num')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->limit($limit)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as &$v){
|
||||
|
||||
$v['surplus_num'] = ($v['success_num'] - $v['have_num'])>0?$v['success_num'] - $v['have_num']:0;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 14:50
|
||||
* @功能说明:用户参与拼团的次数
|
||||
*/
|
||||
public function userCollageCount($user_id){
|
||||
|
||||
$dis[] = ['a.user_id','=',$user_id];
|
||||
|
||||
$dis[] = ['a.status','>=',1];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim b','a.claim_id = b.id','left')
|
||||
->join('lbfarm_v2_claim_collage_start c','a.start_id = c.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title as claim_title,b.cover as claim_cover,c.end_time,c.success_num')
|
||||
->group('a.id')
|
||||
->count();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-16 15:25
|
||||
* @功能说明:用户拼团记录
|
||||
*/
|
||||
public function userCollagePage($dis,$limit=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim b','a.claim_id = b.id','left')
|
||||
->join('lbfarm_v2_claim_collage_start c','a.start_id = c.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title as claim_title,b.cover as claim_cover,c.end_time,c.success_num')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['user_avatar'] = $this->collageUserAvatar($v['start_id'],4);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-16 18:06
|
||||
* @功能说明:拼团用户头像
|
||||
*/
|
||||
public function collageUserAvatar($id,$limit=5){
|
||||
|
||||
$dis[] = ['a.start_id','=',$id];
|
||||
|
||||
$dis[] = ['a.status','>=',1];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_user_list b','a.user_id = b.id','left')
|
||||
->where($dis)
|
||||
->limit($limit)
|
||||
->column('b.avatarUrl');
|
||||
|
||||
return array_values($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-17 16:25
|
||||
* @功能说明:参与拼团
|
||||
*/
|
||||
public function joinCollage($order,$data,$is_start){
|
||||
|
||||
$collage_model = new ClaimCollage();
|
||||
|
||||
if(empty($data)||$data['end_time']<time()){
|
||||
|
||||
return ['code'=>500,'msg'=>'拼团已经结束'];
|
||||
|
||||
}
|
||||
|
||||
$collage = $collage_model->dataInfo(['id'=>$data['atv_id']]);
|
||||
|
||||
if(empty($collage)){
|
||||
|
||||
return ['code'=>500,'msg'=>'拼团已经结束'];
|
||||
|
||||
}
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'atv_id' => $data['atv_id'],
|
||||
|
||||
'is_start'=> 0
|
||||
];
|
||||
//校验参与次数
|
||||
$count = $this->where($dis)->where('status','>',-1)->count();
|
||||
|
||||
if($collage['join_times']<=$count){
|
||||
|
||||
return ['code'=>500,'msg'=>'拼团超过参与次数'];
|
||||
}
|
||||
|
||||
$dis = [
|
||||
|
||||
'start_id' => $data['id']
|
||||
];
|
||||
|
||||
if($data['have_num']>=$data['success_num']){
|
||||
|
||||
return ['code'=>500,'msg'=>'超过拼团人数'];
|
||||
|
||||
}
|
||||
//校验库存
|
||||
$num = $this->where($dis)->where('status','>',-1)->sum('num');
|
||||
|
||||
if($num>=$collage['stock']){
|
||||
|
||||
return ['code'=>500,'msg'=>'超过活动库存'];
|
||||
|
||||
}
|
||||
|
||||
$dis['user_id'] = $order['user_id'];
|
||||
|
||||
$find = $this->where($dis)->where('status','>',-1)->find();
|
||||
|
||||
if(!empty($find)){
|
||||
|
||||
return ['code'=>500,'msg'=>'你已经参加过改拼团了'];
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'claim_id'=> $order['claim_id'],
|
||||
|
||||
'price' => $collage['price'],
|
||||
|
||||
'status' => 0,
|
||||
|
||||
'order_id'=> $order['id'],
|
||||
|
||||
'num' => $order['num'],
|
||||
|
||||
'atv_id' => $data['atv_id'],
|
||||
|
||||
'start_id'=> $data['id'],
|
||||
|
||||
'is_start'=> $is_start,
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
$start_model = new CollageStart();
|
||||
|
||||
$start_model->where(['id'=>$data['id']])->update(['have_order_num'=>Db::Raw('have_order_num+1')]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 17:23
|
||||
* @功能说明:用户是否还能参加该拼团
|
||||
*/
|
||||
public function collageCanJoin($user_id,$start_id){
|
||||
|
||||
$find = $this->where(['user_id'=>$user_id,'start_id'=>$start_id])->where('status','in',[0,1,2])->find();
|
||||
|
||||
if(!empty($find)){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$collage_model = new ClaimCollage();
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.id' => $start_id
|
||||
];
|
||||
|
||||
$data = $collage_model->alias('a')
|
||||
->join('lbfarm_v2_claim_collage_start b','a.id = b.atv_id')
|
||||
->where($dis)
|
||||
->field('b.atv_id,a.join_times')
|
||||
->find();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$data = $data->toArray();
|
||||
|
||||
$count = $this->where(['user_id'=>$user_id,'atv_id'=>$data['atv_id']])->where('status','in',[0,1,2])->count();
|
||||
|
||||
if($data['join_times']<=$count){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
450
app/farm/model/CollageStart.php
Normal file
450
app/farm/model/CollageStart.php
Normal file
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class CollageStart extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_claim_collage_start';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'surplus_num'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:剩余人数
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-19 10:05
|
||||
*/
|
||||
public function getSurplusNumAttr($value,$data){
|
||||
|
||||
if(isset($data['success_num'])&&isset($data['have_num'])){
|
||||
|
||||
return ($data['success_num']-$data['have_num'])>=0?$data['success_num']-$data['have_num']:0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2022-07-01 15:33
|
||||
* @功能说明:
|
||||
*/
|
||||
public function adminDataList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_claim b','a.claim_id = b.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title as claim_title')
|
||||
->group('a.id')
|
||||
->order('a.top desc,a.id')
|
||||
->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-08-16 17:19
|
||||
* @功能说明:认养拼团商品
|
||||
*/
|
||||
public function claimCollageLimit($claim_id,$limit=3,$user_id=0){
|
||||
|
||||
$dis[] = ['end_time','>',time()];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
$dis[] = ['claim_id','=',$claim_id];
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->limit($limit)->select()->toArray();
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$collage_model = new CollageJoin();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as &$v){
|
||||
|
||||
$v['user_info'] = $user_model->dataInfo(['id'=>$v['user_id']],'nickName,avatarUrl');
|
||||
//是否能参与拼团
|
||||
$v['can_join'] = $collage_model->collageCanJoin($user_id,$v['id']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-16 17:19
|
||||
* @功能说明:认养拼团商品
|
||||
*/
|
||||
public function claimCollageList($dis,$page=10){
|
||||
|
||||
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$collage_model = new CollageJoin();
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['user_info'] = $user_model->dataInfo(['id'=>$v['user_id']],'nickName,avatarUrl');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-17 16:25
|
||||
* @功能说明:发起拼团
|
||||
*/
|
||||
public function startCollage($order,$atv){
|
||||
|
||||
$check = $this->startAtvCheck($order['user_id'],$atv['id']);
|
||||
|
||||
if(!empty($check['code'])){
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'claim_id'=> $order['claim_id'],
|
||||
|
||||
'end_time'=> time()+$atv['success_time']*60,
|
||||
|
||||
'price' => $atv['price'],
|
||||
|
||||
'success_num'=> $atv['success_num'],
|
||||
|
||||
'status' => 0,
|
||||
|
||||
'order_id'=> $order['id'],
|
||||
|
||||
'atv_id' => $atv['id'],
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$data= $this->dataInfo(['id'=>$id]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 10:33
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getAtvInfo($atv_id,$claim_id){
|
||||
|
||||
$data = $this->dataInfo(['id'=>$atv_id,'claim_id'=>$claim_id]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 11:45
|
||||
* @功能说明:活动回调
|
||||
*/
|
||||
public function atvResult($order_id){
|
||||
|
||||
$join_model = new CollageJoin();
|
||||
|
||||
$data = $join_model->dataInfo(['order_id'=>$order_id]);
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$this->dataUpdate(['order_id'=>$order_id,'status'=>0],['status'=>1]);
|
||||
|
||||
$join_model->dataUpdate(['order_id'=>$order_id,'status'=>0],['status'=>1]);
|
||||
|
||||
$this->where(['id'=>$data['id']])->update(['have_num'=>Db::Raw('have_num+1')]);
|
||||
|
||||
$this->atvSuccess($data['start_id']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 11:47
|
||||
* @功能说明:拼团活动成功
|
||||
*/
|
||||
public function atvSuccess($id){
|
||||
|
||||
$data = $this->dataInfo(['id'=>$id,'status'=>1]);
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$join_model = new CollageJoin();
|
||||
|
||||
$count = $join_model->where(['start_id'=>$id,'status'=>1])->count();
|
||||
|
||||
if($count>=$data['success_num']){
|
||||
|
||||
$this->dataUpdate(['id'=>$id],['status'=>2,'success_times'=>time()]);
|
||||
|
||||
$join_model->dataUpdate(['start_id'=>$id,'status'=>1],['status'=>2]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 14:24
|
||||
* @功能说明:取消订单
|
||||
*/
|
||||
public function cancelOrderAtvFail($order_id){
|
||||
|
||||
$this->dataUpdate(['order_id'=>$order_id],['status'=>-1]);
|
||||
|
||||
$this->where(['order_id'=>$order_id])->update(['have_order_num'=>Db::Raw('have_order_num+1')]);
|
||||
|
||||
$join_model = new CollageJoin();
|
||||
|
||||
$join_model->dataUpdate(['order_id'=>$order_id],['status'=>-1]);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 13:41
|
||||
* @功能说明:活动失效
|
||||
*/
|
||||
public function initAtv($payConfig){
|
||||
|
||||
$dis[] = ['end_time','<',time()];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
$list = $this->where($dis)->select()->toArray();
|
||||
|
||||
$join_model = new CollageJoin();
|
||||
|
||||
$order_model= new ClaimOrder();
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$value['id']],['status'=>3]);
|
||||
|
||||
if($res!=0){
|
||||
|
||||
$data = $join_model->where(['status'=>1,'start_id'=>$value['id']])->select()->toArray();
|
||||
|
||||
$join_model->dataUpdate(['status'=>1,'start_id'=>$value['id']],['status'=>3]);
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $v){
|
||||
|
||||
$order = $order_model->dataInfo(['id'=>$v['order_id'],'pay_type'=>2]);
|
||||
|
||||
if(!empty($order)){
|
||||
//订单退款
|
||||
$order_model->cancelOrder($order,2,$payConfig);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 15:47
|
||||
* @功能说明:发起开团审核
|
||||
*/
|
||||
public function startAtvCheck($user_id,$atv_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'atv_id' => $atv_id
|
||||
];
|
||||
|
||||
$count = $this->where($dis)->where('status','in',[0,1])->count();
|
||||
|
||||
if(!empty($count)){
|
||||
|
||||
return ['code'=>500,'msg'=>'你有正在进行中或未付款的团'];
|
||||
}
|
||||
|
||||
$collage_model = new ClaimCollage();
|
||||
|
||||
$data = $collage_model->dataInfo(['id'=>$atv_id,'status'=>1]);
|
||||
|
||||
if(empty($data)||$data['end_time']<time()){
|
||||
|
||||
return ['code'=>500,'msg'=>'活动已经结束'];
|
||||
|
||||
}
|
||||
|
||||
if($count>=$data['start_times']){
|
||||
|
||||
return ['code'=>500,'msg'=>'超过发起拼团次数'];
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @功能说明:获取用户正在发起中的拼团
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-18 16:52
|
||||
*/
|
||||
public function userCollageIngData($user_id,$claim_id){
|
||||
|
||||
$data = $this->dataInfo(['user_id'=>$user_id,'status'=>1,'claim_id'=>$claim_id]);
|
||||
|
||||
$collage_model = new CollageJoin();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
$data['user_avatar'] = $collage_model->collageUserAvatar($data['id'],4);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
462
app/farm/model/Config.php
Normal file
462
app/farm/model/Config.php
Normal file
@@ -0,0 +1,462 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use app\BaseModel;
|
||||
use app\shop\model\FreightTemplate;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class Config extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_config';
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-01 15:46
|
||||
*/
|
||||
public function getAppBannerAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
$value = explode(',',$value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
/**
|
||||
* @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();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
$this->dataAdd($dis);
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
}
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-08 14:12
|
||||
* @功能说明:获取运费
|
||||
*/
|
||||
public function getSendPrice($distance,$uniacid){
|
||||
|
||||
$config = $this->dataInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
$y_distance = $distance - $config['start_distance'];
|
||||
|
||||
if($y_distance<0){
|
||||
|
||||
return $config['start_price'];
|
||||
|
||||
}else{
|
||||
|
||||
// return round($config['start_price']+$y_distance/$config['renew_distance']*$config['renew_price'],2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $address_id
|
||||
* @param $goods_list
|
||||
* @param int $type
|
||||
* @功能说明:计算运费
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-08 17:35
|
||||
*/
|
||||
public function getTotalSendPrice($address_id,$goods_list,$type=1){
|
||||
|
||||
$address_model = new Address();
|
||||
|
||||
$address = $address_model->dataInfo(['id'=>$address_id]);
|
||||
|
||||
if(empty($address)){
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'地址信息错误'];
|
||||
}
|
||||
|
||||
$frist_price = $frist_id = $addprice = 0;
|
||||
|
||||
if(!empty($goods_list)){
|
||||
|
||||
foreach ($goods_list as &$goods_info){
|
||||
//获取
|
||||
$tmpl_data = $this->getSendTmp($goods_info['send_tmpl_id'],$address,$type);
|
||||
|
||||
if((!empty($tmpl_data['code'])&&$tmpl_data['code']==500)||empty($tmpl_data)){
|
||||
|
||||
return $tmpl_data;
|
||||
}
|
||||
|
||||
$tmpl = $tmpl_data['tmpl'];
|
||||
//找到首费最大的模版
|
||||
if($tmpl['start_price']>$frist_price){
|
||||
|
||||
$frist_price = $tmpl['start_price'];
|
||||
|
||||
$frist_id = $tmpl['id'];
|
||||
}
|
||||
//获取有多少个模版
|
||||
if(empty($tmpl_arr[$tmpl['id']])){
|
||||
|
||||
$tmpl_arr[$tmpl['id']] = $tmpl;
|
||||
}
|
||||
|
||||
$tmpl_unit = !empty($tmpl_arr[$tmpl['id']]['tmpl_unit'])?$tmpl_arr[$tmpl['id']]['tmpl_unit']:0;
|
||||
|
||||
$unit = $tmpl_data['type']==1?$goods_info['goods_num']:$goods_info['total_weight'];
|
||||
//计算每个模版的重量或者件数
|
||||
$tmpl_arr[$tmpl['id']]['tmpl_unit'] = $tmpl_unit+$unit;
|
||||
|
||||
}
|
||||
|
||||
foreach ($tmpl_arr as $tmpl){
|
||||
|
||||
if($tmpl['id']==$frist_id){
|
||||
//1按件数 2按重量
|
||||
$add_num = ($tmpl['tmpl_unit'] - $tmpl['start_num'])>0?$tmpl['tmpl_unit'] - $tmpl['start_num']:0;
|
||||
|
||||
}else{
|
||||
|
||||
$add_num = $tmpl['tmpl_unit'];
|
||||
|
||||
}
|
||||
|
||||
$add_num = $tmpl['add_num']>0?ceil($add_num/$tmpl['add_num']):0;
|
||||
|
||||
$price = $add_num*$tmpl['add_price'];
|
||||
|
||||
$addprice += $price;
|
||||
|
||||
// dump($addprice,$frist_price);exit;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// dump($addprice,$frist_price);exit;
|
||||
return round($addprice+$frist_price,2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-09 13:50
|
||||
* @功能说明:获取模版
|
||||
*/
|
||||
public function getSendTmp($send_tmpl_id,$address,$type){
|
||||
|
||||
$tmpl_model = new FreightTemplate();
|
||||
|
||||
$tmpl = $tmpl_model->dataInfo(['id'=>$send_tmpl_id]);
|
||||
|
||||
if(empty($tmpl)){
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'商品未管理模版'];
|
||||
}
|
||||
|
||||
if(!empty($tmpl['config'])){
|
||||
|
||||
foreach ($tmpl['config'] as $value){
|
||||
|
||||
if(in_array($address['province'],$value['province'])){
|
||||
|
||||
$tmpl['tmpl'] = $value;
|
||||
|
||||
return $tmpl;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'地址未在配送范围内'];
|
||||
|
||||
}else{
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'地址未在配送范围内'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-22 17:51
|
||||
* @功能说明:获取商品运费信息
|
||||
*/
|
||||
public function getGoodsSendPrice($address_id,$goods_info,$type=1,$data=1){
|
||||
|
||||
$tmpl_model = new FreightTemplate();
|
||||
|
||||
$address_model = new Address();
|
||||
|
||||
$tmpl = $tmpl_model->dataInfo(['id'=>$goods_info['send_tmpl_id']]);
|
||||
|
||||
if(empty($tmpl)){
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'商品未管理模版'];
|
||||
}
|
||||
|
||||
$address = $address_model->dataInfo(['id'=>$address_id]);
|
||||
|
||||
if(empty($address)){
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'地址信息错误'];
|
||||
}
|
||||
|
||||
if(!empty($tmpl['config'])){
|
||||
|
||||
foreach ($tmpl['config'] as $value){
|
||||
|
||||
if(in_array($address['province'],$value['province'])){
|
||||
//1按件数 2按重量
|
||||
$unit = $tmpl['type']==1?$goods_info['goods_num']:$goods_info['total_weight'];
|
||||
|
||||
$add_num = ($unit - $value['start_num'])>0?$unit - $value['start_num']:0;
|
||||
|
||||
$add_num = $value['add_num']>0?ceil($add_num/$value['add_num']):0;
|
||||
|
||||
$price = round($value['start_price']+$add_num*$value['add_price'],2);
|
||||
|
||||
if($data==1){
|
||||
|
||||
return $price;
|
||||
|
||||
}else{
|
||||
|
||||
return ['price'=>$price,'type'=>$tmpl['type']];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'地址未在配送范围内'];
|
||||
|
||||
}else{
|
||||
|
||||
return $type==1?0:['code'=>500,'msg'=>'地址未在配送范围内'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 10:58
|
||||
* @功能说明:获取天气情况,默认甘孜
|
||||
*/
|
||||
public function getWeather($uniacid,$lat='30.04932',$lang='101.9625'){
|
||||
|
||||
$config = $this->dataInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
$key = $lat.'-'.$lang;
|
||||
|
||||
$weather = getCache($key,$this->_uniacid);
|
||||
|
||||
if(empty($weather)){
|
||||
|
||||
$url = 'https://apis.map.qq.com/ws/geocoder/v1/?location='.$lat.','.$lang;
|
||||
|
||||
$url = $url.'&key='.$config['map_secret'];
|
||||
|
||||
$location = longbingCurl($url,[]);
|
||||
|
||||
$location = json_decode($location,true);
|
||||
|
||||
if(!empty($location['result']['address_component'])){
|
||||
|
||||
$location = $location['result']['address_component'];
|
||||
|
||||
if(!empty($location['province'])){
|
||||
|
||||
$province = $location['province'];
|
||||
|
||||
$city = $location['city'];
|
||||
|
||||
$county = $location['district'];
|
||||
|
||||
$url = 'https://wis.qq.com/weather/common?source=pc&weather_type=observe|forecast_24h|air&province='.$province.'&city='.$city.'&county='.$county;
|
||||
|
||||
$weather = file_get_contents($url);
|
||||
|
||||
$weather = @json_decode($weather,true);
|
||||
|
||||
setCache($key,$weather,7200,$this->_uniacid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $weather;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-25 11:16
|
||||
* @功能说明:获取天气情况,默认甘孜
|
||||
*/
|
||||
public function getPlaceWeather($province='四川',$city='甘孜'){
|
||||
|
||||
$key = $province.'-'.$city;
|
||||
|
||||
$weather = getCache($key,$this->_uniacid);
|
||||
|
||||
if(empty($weather)){
|
||||
|
||||
$url = 'https://wis.qq.com/weather/common?source=pc&province='.$province.'&city='.$city.'&weather_type=observe|forecast_24h';
|
||||
|
||||
$weather = file_get_contents($url);
|
||||
|
||||
$weather = @json_decode($weather,true);
|
||||
|
||||
setCache($key,$weather,7200,$this->_uniacid);
|
||||
}
|
||||
|
||||
return $weather;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $str_phone
|
||||
* @param $uniacid
|
||||
* @功能说明:发送短信验证码
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-14 10:43
|
||||
*/
|
||||
public function sendSms($str_phone,$uniacid){
|
||||
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $uniacid
|
||||
];
|
||||
|
||||
$config = $this->dataInfo($dis);
|
||||
|
||||
$keyId = $config['short_id'];
|
||||
|
||||
$keySecret = $config['short_secret'];
|
||||
|
||||
$SignName = $config['short_sign'];
|
||||
|
||||
$TemplateCode = $config['short_code'];
|
||||
|
||||
if(empty($keyId)||empty($keySecret)||empty($TemplateCode)){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$code = mt_rand(100000,999999);
|
||||
|
||||
setCache($str_phone,$code,600,$uniacid);
|
||||
|
||||
AlibabaCloud::accessKeyClient($keyId, $keySecret)->regionId('cn-hangzhou') // replace regionId as you need
|
||||
->asDefaultClient();
|
||||
|
||||
try {
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Dysmsapi')
|
||||
// ->scheme('https') // https | http
|
||||
->version('2017-05-25')
|
||||
->action('SendSms')
|
||||
->method('POST')
|
||||
->host('dysmsapi.aliyuncs.com')
|
||||
->options([
|
||||
'query' => [
|
||||
'RegionId' => "default",
|
||||
'PhoneNumbers' => $str_phone,
|
||||
//必填项 签名(需要在阿里云短信服务后台申请)
|
||||
'SignName' => $SignName,
|
||||
//必填项 短信模板code (需要在阿里云短信服务后台申请)
|
||||
'TemplateCode' => $TemplateCode,
|
||||
//如果在短信中添加了${code} 变量则此项必填 要求为JSON格式
|
||||
'TemplateParam' => "{'code':$code}",
|
||||
],
|
||||
])
|
||||
->request();
|
||||
|
||||
|
||||
return !empty($result)?$result->toArray():[];
|
||||
} catch(Exception $e)
|
||||
{}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
469
app/farm/model/Coupon.php
Normal file
469
app/farm/model/Coupon.php
Normal file
@@ -0,0 +1,469 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\member\model\Level;
|
||||
use think\facade\Db;
|
||||
|
||||
class Coupon extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_coupon';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
|
||||
'send_count',
|
||||
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-15 15:22
|
||||
* @功能说明:已派发多少张
|
||||
*/
|
||||
public function getSendCountAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$record_model = new CouponRecord();
|
||||
|
||||
$count = $record_model->where(['coupon_id'=>$data['id']])->sum('num');
|
||||
|
||||
return $count;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
// $data_data = $data;
|
||||
|
||||
// if(isset($data['service'])){
|
||||
//
|
||||
// unset($data['service']);
|
||||
// }
|
||||
//
|
||||
// if(isset($data['member_level'])){
|
||||
//
|
||||
// unset($data['member_level']);
|
||||
// }
|
||||
//
|
||||
// if(isset($data['shop_goods'])){
|
||||
//
|
||||
// unset($data['shop_goods']);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
// $this->updateSome($id,$data_data);
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
// $data_data = $data;
|
||||
|
||||
// if(isset($data['service'])){
|
||||
//
|
||||
// unset($data['service']);
|
||||
// }
|
||||
//
|
||||
// if(isset($data['member_level'])){
|
||||
//
|
||||
// unset($data['member_level']);
|
||||
// }
|
||||
//
|
||||
// if(isset($data['shop_goods'])){
|
||||
//
|
||||
// unset($data['shop_goods']);
|
||||
// }
|
||||
//
|
||||
// if(isset($data['restaurant_goods'])){
|
||||
//
|
||||
// unset($data['restaurant_goods']);
|
||||
// }
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
// $this->updateSome($dis['id'],$data_data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-01 15:40
|
||||
*/
|
||||
public function updateSome($id,$data){
|
||||
|
||||
$server = new \app\shop\server\Coupon();
|
||||
|
||||
$s_model = new CouponService();
|
||||
|
||||
$coupon_member_model = new CouponMember();
|
||||
|
||||
$goods_model = new \app\shop\model\Goods();
|
||||
|
||||
$r_goods_model = new \app\restaurant\model\Goods();
|
||||
|
||||
$coupon_member_model->where(['coupon_id'=>$id])->delete();
|
||||
|
||||
$s_model->where(['coupon_id'=>$id])->delete();
|
||||
//赛车服务
|
||||
$server->addObserver($s_model);
|
||||
//会员
|
||||
$server->addObserver($coupon_member_model);
|
||||
//商城商品
|
||||
$server->addObserver($goods_model);
|
||||
//
|
||||
$server->addObserver($r_goods_model);
|
||||
|
||||
$res = $server->notify($id,$data);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uniacid
|
||||
* @param $spe
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 13:35
|
||||
*/
|
||||
public function updateSomev2($id,$uniacid,$goods,$member_level,$shop_goods){
|
||||
|
||||
$s_model = new CouponService();
|
||||
|
||||
$coupon_member_model = new CouponMember();
|
||||
|
||||
$s_model->where(['coupon_id'=>$id])->delete();
|
||||
|
||||
if(!empty($goods)){
|
||||
|
||||
foreach ($goods as $value){
|
||||
|
||||
$insert['uniacid'] = $uniacid;
|
||||
|
||||
$insert['coupon_id'] = $id;
|
||||
|
||||
$insert['goods_id'] = $value;
|
||||
|
||||
$s_model->dataAdd($insert);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($shop_goods)){
|
||||
|
||||
foreach ($shop_goods as $value){
|
||||
|
||||
$insert['uniacid'] = $uniacid;
|
||||
|
||||
$insert['coupon_id'] = $id;
|
||||
|
||||
$insert['goods_id'] = $value;
|
||||
|
||||
$insert['scene'] = 2;
|
||||
|
||||
$s_model->dataAdd($insert);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$coupon_member_model->where(['coupon_id'=>$id])->delete();
|
||||
|
||||
if(!empty($member_level)){
|
||||
|
||||
foreach ($member_level as &$value){
|
||||
|
||||
$inserts['uniacid'] = $uniacid;
|
||||
|
||||
$inserts['coupon_id'] = $id;
|
||||
|
||||
$inserts['member_level'] = $value;
|
||||
|
||||
$coupon_member_model->dataAdd($inserts);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,$filed='*'){
|
||||
|
||||
$data = $this->where($dis)->field($filed)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-09 23:22
|
||||
* @功能说明:计算优惠券可以优惠多少钱
|
||||
*/
|
||||
|
||||
public function getDicountPrice($order_goods,$coupon_id=0){
|
||||
|
||||
// $coupon_se_model = new CouponService();
|
||||
//暂时没有商品限制 先注释
|
||||
// $goods_id = $coupon_se_model->where(['coupon_id'=>$coupon_id,'type'=>1,'scene'=>$scene])->column('goods_id');
|
||||
|
||||
$price = 0;
|
||||
|
||||
foreach ($order_goods as $v){
|
||||
|
||||
foreach ($v['goods_list'] as $vs){
|
||||
|
||||
// if(in_array($vs['goods_list'],$goods_id)){
|
||||
|
||||
$price += $v['car_price'];
|
||||
//暂时没有商品限制
|
||||
$goods_id[] = $vs['goods_id'];
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$data['discount'] = $price;
|
||||
|
||||
$data['goods_id'] = $goods_id;
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-09 23:37
|
||||
* @功能说明:订单优惠券
|
||||
*/
|
||||
public function orderCouponData($order_goods,$coupon_id,$scene=1){
|
||||
|
||||
if(empty($coupon_id)){
|
||||
|
||||
return $order_goods;
|
||||
}
|
||||
|
||||
$coupon_record_model = new CouponRecord();
|
||||
|
||||
$info = $coupon_record_model->dataInfo(['id'=>$coupon_id]);
|
||||
//是否被使用或者过期
|
||||
if(empty($info)||$info['status']!=1){
|
||||
|
||||
return $order_goods;
|
||||
}
|
||||
//不支持商城
|
||||
if($scene==1&&$info['is_shop']!=1){
|
||||
|
||||
return $order_goods;
|
||||
|
||||
}
|
||||
//不支持土地
|
||||
if($scene==2&&$info['is_land']!=1){
|
||||
|
||||
return $order_goods;
|
||||
|
||||
}
|
||||
//不支持认养
|
||||
if($scene==3&&$info['is_claim']!=1){
|
||||
|
||||
return $order_goods;
|
||||
|
||||
}
|
||||
if($info['start_time']<time()&&$info['end_time']>time()){
|
||||
//是否满足满减条件
|
||||
if($info['full']>$order_goods['car_price']){
|
||||
|
||||
return $order_goods;
|
||||
}
|
||||
|
||||
$total_discount = 0;
|
||||
|
||||
foreach ($order_goods['list'] as $ks=> $vs){
|
||||
|
||||
$ks_discount = 0;
|
||||
|
||||
foreach ($vs['goods_list'] as &$v){
|
||||
|
||||
$bin = $v['true_price']/$order_goods['car_price'];
|
||||
//该商品减去的折扣
|
||||
$discount = $bin*$info['discount']<$v['true_price']?$bin*$info['discount']:$v['true_price'];
|
||||
//总计折扣
|
||||
$total_discount+=$discount;
|
||||
|
||||
$ks_discount +=$discount;
|
||||
|
||||
$v['true_price'] = round($v['true_price']-$discount,2);
|
||||
|
||||
}
|
||||
|
||||
$order_goods['list'][$ks]['coupon_discount'] = $ks_discount;
|
||||
|
||||
}
|
||||
|
||||
$total_discount = $info['full']>$info['discount']?$info['discount']:round($total_discount,2);
|
||||
|
||||
$order_goods['total_discount'] = round($total_discount,2);
|
||||
|
||||
$order_goods['coupon_id'] = $coupon_id;
|
||||
|
||||
}
|
||||
|
||||
return $order_goods;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-13 11:58
|
||||
* @功能说明:用户可用的优惠券
|
||||
*/
|
||||
public function canUseCoupon($user_id,$order_price,$type=1){
|
||||
|
||||
$coupon_model = new CouponRecord();
|
||||
|
||||
$dis = [
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
//商城支持
|
||||
$dis_type = 'is_shop';
|
||||
break;
|
||||
case 2:
|
||||
//土地支持
|
||||
$dis_type = 'is_land';
|
||||
|
||||
break;
|
||||
case 3:
|
||||
//认养支持
|
||||
$dis_type = 'is_claim';
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
$coupon_model->where($dis)->where('end_time','<',time())->update(['status'=>3]);
|
||||
|
||||
$dis[$dis_type] = 1;
|
||||
|
||||
$list = $coupon_model->where($dis)->where('full','<=',$order_price)->column('id');
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-28 10:50
|
||||
* @功能说明:商城用户可以领取的优惠券
|
||||
*/
|
||||
public function shopCanGetCoupon($uniacid,$user_id,$page=10){
|
||||
|
||||
$record_model = new CouponRecord();
|
||||
|
||||
$id = $record_model->where(['user_id'=>$user_id])->column('coupon_id');
|
||||
|
||||
$dis = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'status' => 1,
|
||||
|
||||
'send_type'=> 2
|
||||
|
||||
];
|
||||
|
||||
$where[] = ['time_limit','=',1];
|
||||
|
||||
$where[] = ['end_time','>',time()];
|
||||
|
||||
|
||||
$data = $this->where($dis)->where('id','not in',$id)->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
368
app/farm/model/CouponRecord.php
Normal file
368
app/farm/model/CouponRecord.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\member\model\Level;
|
||||
use think\facade\Db;
|
||||
|
||||
class CouponRecord extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_coupon_record';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
];
|
||||
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-15 14:37
|
||||
* @功能说明:后台列表
|
||||
*/
|
||||
public function adminDataList($dis,$page=10,$where=[]){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('shequshop_school_cap_list b','a.cap_id = b.id')
|
||||
->where($dis)
|
||||
->where(function ($query) use ($where){
|
||||
$query->whereOr($where);
|
||||
})
|
||||
->field('a.*,b.store_name,b.store_img,b.name,b.mobile')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-15 14:37
|
||||
* @功能说明:后台审核详情
|
||||
*/
|
||||
public function adminDataInfo($dis){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('shequshop_school_cap_list b','a.cap_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.store_name,b.store_img,b.school_name,b.mobile')
|
||||
->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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: 2021-04-08 17:08
|
||||
* @功能说明:审核中
|
||||
*/
|
||||
public function shIng($cap_id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'cap_id' => $cap_id,
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$count = $this->where($dis)->count();
|
||||
|
||||
return $count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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: 2021-07-06 00:02
|
||||
* @功能说明:用户订单数
|
||||
*/
|
||||
public function couponCount($user_id){
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
$dis[] = ['end_time','>',time()];
|
||||
|
||||
$data = $this->where($dis)->sum('num');
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-08 11:57
|
||||
* @功能说明:初始化
|
||||
*/
|
||||
public function initCoupon($uniacid){
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
$dis[] = ['uniacid','=',$uniacid];
|
||||
|
||||
$dis[] = ['end_time','<',time()];
|
||||
|
||||
$res = $this->dataUpdate($dis,['status'=>3]);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-12 15:36
|
||||
* @功能说明:派发优惠券
|
||||
*/
|
||||
public function recordAdd($coupon_id,$user_id,$num=1,$user_get=0,$record_id=0){
|
||||
|
||||
$coupon_model = new Coupon();
|
||||
|
||||
$coupon = $coupon_model->dataInfo(['id'=>$coupon_id]);
|
||||
//用户自己领取的优惠券
|
||||
if($user_get==1){
|
||||
|
||||
if($coupon['send_type']!=2){
|
||||
|
||||
return ['code'=>500,'msg'=>'优惠券已下架'];
|
||||
|
||||
}
|
||||
|
||||
if($coupon['stock']<$num){
|
||||
|
||||
return ['code'=>500,'msg'=>'库存不足'];
|
||||
}
|
||||
//判断是否领取过
|
||||
$have = $this->dataInfo(['user_id'=>$user_id,'coupon_id'=>$coupon_id]);
|
||||
|
||||
if(!empty($have)){
|
||||
|
||||
return ['code'=>500,'msg'=>'你已经领取过了'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $coupon['uniacid'],
|
||||
|
||||
'user_id' => $user_id,
|
||||
|
||||
'coupon_id' => $coupon_id,
|
||||
|
||||
'title' => $coupon['title'],
|
||||
|
||||
'type' => $coupon['type'],
|
||||
|
||||
'full' => $coupon['full'],
|
||||
|
||||
'discount' => $coupon['discount'],
|
||||
|
||||
'rule' => $coupon['rule'],
|
||||
|
||||
'text' => $coupon['text'],
|
||||
|
||||
'is_shop' => $coupon['is_shop'],
|
||||
|
||||
'is_land' => $coupon['is_land'],
|
||||
|
||||
'is_claim' => $coupon['is_claim'],
|
||||
|
||||
'num' => $num,
|
||||
|
||||
'record_id' => $record_id,
|
||||
|
||||
'start_time'=> $coupon['time_limit']==2?time():$coupon['start_time'],
|
||||
|
||||
'end_time' => $coupon['time_limit']==2?time()+$coupon['day']*86400:$coupon['end_time'],
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
if($coupon['send_type']==2){
|
||||
//修改优惠券库存
|
||||
$res = $coupon_model->dataUpdate(['id'=>$coupon_id,'i'=>$coupon['i']],['stock'=>$coupon['stock']-$num,'i'=>$coupon['i']+1]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return ['code'=>500,'msg'=>'领取失败'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-08-29 23:02
|
||||
* @功能说明:退换优惠券
|
||||
*/
|
||||
public function couponRefund($order_id){
|
||||
|
||||
$order_model = new Order();
|
||||
|
||||
$coupon_id = $order_model->where(['id'=>$order_id])->value('coupon_id');
|
||||
|
||||
if(!empty($coupon_id)){
|
||||
|
||||
$this->dataUpdate(['id'=>$coupon_id],['status'=>1,'use_time'=>0,'order_id'=>0]);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-13 09:34
|
||||
* @功能说明:使用优惠券
|
||||
*/
|
||||
public function couponUse($coupon_id,$order_id=0,$use_type=0){
|
||||
|
||||
$record = $this->dataInfo(['id'=>$coupon_id]);
|
||||
|
||||
if($record['num']>1){
|
||||
|
||||
$this->dataUpdate(['id'=>$coupon_id],['num'=>$record['num']-1]);
|
||||
|
||||
unset($record['id']);
|
||||
|
||||
if(isset($record['goods'])){
|
||||
|
||||
unset($record['goods']);
|
||||
}
|
||||
|
||||
if(isset($record['shop_goods'])){
|
||||
|
||||
unset($record['shop_goods']);
|
||||
}
|
||||
|
||||
if(isset($record['restaurant_goods'])){
|
||||
|
||||
unset($record['restaurant_goods']);
|
||||
}
|
||||
|
||||
$record['pid'] = $coupon_id;
|
||||
|
||||
$record['num'] = 1;
|
||||
|
||||
$record['status'] = 2;
|
||||
|
||||
$record['use_time'] = time();
|
||||
|
||||
$record['order_id'] = $order_id;
|
||||
|
||||
$record['use_type'] = $use_type;
|
||||
|
||||
$this->insert($record);
|
||||
|
||||
$coupon_id = $this->getLastInsID();
|
||||
|
||||
}else{
|
||||
|
||||
$this->dataUpdate(['id'=>$coupon_id],['status'=>2,'use_time'=>time(),'order_id'=>$order_id,'use_type'=>$use_type]);
|
||||
|
||||
}
|
||||
//带客有礼 给分享者发券
|
||||
if(!empty($record['record_id'])){
|
||||
|
||||
$atv_model = new BagRecord();
|
||||
|
||||
$atv_info = $atv_model->dataInfo(['id'=>$record['record_id']]);
|
||||
|
||||
$res = $this->recordAdd($atv_info['share_coupon'],$atv_info['share_user']);
|
||||
}
|
||||
|
||||
return $coupon_id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
338
app/farm/model/Evaluate.php
Normal file
338
app/farm/model/Evaluate.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\banquet\model\Place;
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Evaluate extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_evaluate_list';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'order_info'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-10 17:36
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getOrderInfoAttr($value,$data){
|
||||
|
||||
if(isset($data['type'])&&isset($data['order_id'])&&isset($data['farmer_id'])){
|
||||
|
||||
$model = $this->getTypeModel($data['type'],2);
|
||||
|
||||
$info = $model->dataInfo(['id'=>$data['order_id']]);
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
|
||||
$info['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['farmer_id']],'title');
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-09 17:14
|
||||
* @功能说明:转换图片格式
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
|
||||
}else{
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-10 17:37
|
||||
* @功能说明:根据type获取模型
|
||||
*/
|
||||
public function getTypeModel($type,$is_order=1){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
|
||||
$model = new ClaimOrder();
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$model = new LandOrder();
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$model = $is_order ==1?new ShopOrderGoods():new ShopOrder();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$model = new ClaimOrder();
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-10 13:33
|
||||
* @功能说明:评价管理
|
||||
*/
|
||||
public function adminList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_farmer b','a.farmer_id = b.id','left')
|
||||
->join('lbfarm_user_list c','a.user_id = c.id','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.title,c.nickName,c.avatarUrl')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-11 10:04
|
||||
* @功能说明:根据type获取key
|
||||
*/
|
||||
public function getObjKey($type){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
|
||||
$key = 'claim_id';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
$key = 'land_id';
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$key = 'goods_id';
|
||||
|
||||
break;
|
||||
default:
|
||||
$key = 'claim_id';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $key;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-11 09:53
|
||||
* @功能说明:评价列表
|
||||
*/
|
||||
public function goodsEvaluateList($goods_id,$type,$is_goods=0){
|
||||
|
||||
$order_model = $this->getTypeModel($type);
|
||||
|
||||
$key = $this->getObjKey($type);
|
||||
|
||||
$dis = [
|
||||
|
||||
// 'pay_type' => 7,
|
||||
|
||||
$key => $goods_id
|
||||
];
|
||||
|
||||
if($type==3){
|
||||
|
||||
$order_id = $order_model->where($dis)->column('order_id');
|
||||
|
||||
}else{
|
||||
|
||||
$order_id = $order_model->where($dis)->column('id');
|
||||
}
|
||||
|
||||
$where[] = ['status','>',-1];
|
||||
|
||||
$where[] = ['order_id','in',$order_id];
|
||||
|
||||
$where[] = ['type','=',$type];
|
||||
|
||||
$dis_where = $where;
|
||||
|
||||
if($is_goods==1){
|
||||
|
||||
$where[] = ['star','>=',3];
|
||||
|
||||
}
|
||||
|
||||
if($is_goods==2){
|
||||
|
||||
$where[] = ['star','<',3];
|
||||
|
||||
}
|
||||
|
||||
$data = $this->dataList($where);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['user_info'] = $user_model->where(['id'=>$v['user_id']])->field('nickName,avatarUrl')->find();
|
||||
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data['good_count'] = $this->where($dis_where)->where('star','>=',3)->count();
|
||||
|
||||
$data['bad_count'] = $this->where($dis_where)->where('star','<',3)->count();
|
||||
|
||||
$data['all_count'] = $this->where($dis_where)->count();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $place_id
|
||||
* @功能说明:修改场地的评分
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-11 15:49
|
||||
*/
|
||||
public function updateFarmerStar($farmer_id){
|
||||
|
||||
$dis[] = ['farmer_id','=',$farmer_id];
|
||||
|
||||
$dis[] = ['status','>',-1];
|
||||
|
||||
$find = $this->where($dis)->find();
|
||||
|
||||
$star = $this->where($dis)->avg('star');
|
||||
|
||||
$star = !empty($find)?$star:5;
|
||||
|
||||
$farmr_model = new Farmer();
|
||||
|
||||
$res = $farmr_model->dataUpdate(['id'=>$farmer_id],['star'=>$star]);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
344
app/farm/model/Farmer.php
Normal file
344
app/farm/model/Farmer.php
Normal file
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Farmer extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_farmer';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'time_status'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-02 17:12
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getTimeStatusAttr($value,$data){
|
||||
|
||||
if(!empty($data['start_time'])&&!empty($data['end_time'])){
|
||||
|
||||
$start_time = strtotime($data['start_time']);
|
||||
|
||||
$end_time = strtotime($data['end_time']);
|
||||
|
||||
if($start_time<time()&&$end_time>time()){
|
||||
|
||||
return 1;
|
||||
}else{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-30 11:22
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-30 11:22
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getIdcardImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @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:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataDistanceList($dis,$alh,$alhs=[],$page=10){
|
||||
|
||||
$data = $this->where($dis)->where($alhs)->field(['*',$alh])->order('distance asc,id desc')->paginate($page)->toArray();
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis,$file='*'){
|
||||
|
||||
$data = $this->where($dis)->field($file)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-22 11:30
|
||||
* @功能说明:检查用户是否是地主
|
||||
*/
|
||||
public function landlordCheck($user_id){
|
||||
|
||||
$cap_dis[] = ['user_id','=',$user_id];
|
||||
|
||||
$cap_dis[] = ['type','=',1];
|
||||
|
||||
$cap_dis[] = ['status','in',[2,3]];
|
||||
|
||||
$farmer_model = new \app\farm\model\Farmer();
|
||||
//查看是否是团长
|
||||
$cap_info = $farmer_model->dataInfo($cap_dis);
|
||||
|
||||
$is_landlord = 1;
|
||||
|
||||
if(empty($cap_info)){
|
||||
|
||||
$order_model = new LandOrder();
|
||||
|
||||
$where[] = ['pay_type','>',1];
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
//是否有土地订单
|
||||
$order = $order_model->dataInfo($where);
|
||||
|
||||
if(empty($order)){
|
||||
|
||||
$is_landlord = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$user_model->dataUpdate(['id'=>$user_id],['is_landlord'=>$is_landlord]);
|
||||
|
||||
return $is_landlord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-22 11:53
|
||||
* @功能说明:初始化地主表
|
||||
*/
|
||||
public function initLandLord($data,$uniacid){
|
||||
|
||||
$dis = [
|
||||
|
||||
'type' => 2,
|
||||
|
||||
'user_id' => $data['user_id'],
|
||||
|
||||
'uniacid' => $uniacid
|
||||
];
|
||||
|
||||
$find = $this->dataInfo($dis);
|
||||
|
||||
if(empty($find)){
|
||||
|
||||
$dis['status'] = 2;
|
||||
|
||||
$dis['title'] = $data['title'];
|
||||
|
||||
$dis['cover'] = $data['cover'];
|
||||
|
||||
$dis['address'] = $data['address'];
|
||||
|
||||
$dis['lat'] = $data['lat'];
|
||||
|
||||
$dis['lng'] = $data['lng'];
|
||||
|
||||
$dis['desc'] = $data['desc'];
|
||||
|
||||
$dis['mobile'] = $data['mobile'];
|
||||
|
||||
$this->dataAdd($dis);
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$user_model->dataUpdate(['id'=>$data['user_id']],['is_landlord'=>1]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-10-21 15:21
|
||||
* @功能说明:保留两位小数
|
||||
*/
|
||||
public function getDistanceAttr($value){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
if($value>1000){
|
||||
|
||||
$value = $value/1000;
|
||||
|
||||
$value = round($value,2);
|
||||
|
||||
$value = $value.'km';
|
||||
}else{
|
||||
|
||||
$value = round($value,2);
|
||||
|
||||
$value = $value.'m';
|
||||
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-28 14:08
|
||||
* @功能说明:添加商品时农场主下拉框
|
||||
*/
|
||||
public function goodsFarmerSelect($user_id){
|
||||
|
||||
$land_order_model = new LandOrder();
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
|
||||
$dis[] = ['pay_type','>',1];
|
||||
//购买土地对农场主id
|
||||
$order_farmer = $land_order_model->where($dis)->column('farmer_id');
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
|
||||
$where[] = ['status','in',[2,3]];
|
||||
//如果自己是农场主
|
||||
$farmer = $this->where($where)->column('id');
|
||||
|
||||
$order_farmer = array_merge($order_farmer,$farmer);
|
||||
|
||||
return $order_farmer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-28 16:06
|
||||
* @功能说明:
|
||||
*/
|
||||
public function farmerId($uniacid){
|
||||
|
||||
$dis = [
|
||||
|
||||
'status' => 2,
|
||||
|
||||
'uniacid'=> $uniacid
|
||||
];
|
||||
|
||||
$id = $this->where($dis)->column('id');
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
872
app/farm/model/FinanceWater.php
Normal file
872
app/farm/model/FinanceWater.php
Normal file
@@ -0,0 +1,872 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use function Qcloud\Cos\endWith;
|
||||
use think\facade\Db;
|
||||
|
||||
class FinanceWater extends BaseModel
|
||||
{
|
||||
|
||||
//1认养 2认养退款 3土地 4土地退款 5养殖 6养殖管理 7提现 8商城 9商城退款 10认养配送 11认养配送退款
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_farmer_finance_water';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'type_text',
|
||||
|
||||
'create_time_text'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**]
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-09 16:40
|
||||
* @功能说明:转时间格式
|
||||
*/
|
||||
public function getCreateTimeTextAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return date('Y-m-d H:i:s',$data['create_time']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-09 16:33
|
||||
* @功能说明:类型描述
|
||||
*/
|
||||
public function getTypeTextAttr($value,$data){
|
||||
|
||||
if(isset($data['type'])){
|
||||
|
||||
$text = $this->getTypeData($data['type']);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-09 15:52
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getTypeData($type){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
|
||||
$text = '认养订单收入';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
$text = '认养订单退款';
|
||||
|
||||
break;
|
||||
case 3:
|
||||
|
||||
$text = '土地订单收入';
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
||||
$text = '土地订单退款';
|
||||
|
||||
break;
|
||||
case 5:
|
||||
|
||||
$text = '养殖';
|
||||
|
||||
break;
|
||||
case 6:
|
||||
|
||||
$text = '养殖订单收入';
|
||||
|
||||
break;
|
||||
case 7:
|
||||
|
||||
$text = '提现';
|
||||
|
||||
break;
|
||||
case 8:
|
||||
|
||||
$text = '商城订单收入';
|
||||
|
||||
break;
|
||||
case 9:
|
||||
|
||||
$text = '商城退款';
|
||||
|
||||
break;
|
||||
case 10:
|
||||
|
||||
$text = '认养配送订单收入';
|
||||
|
||||
break;
|
||||
case 11:
|
||||
|
||||
$text = '认养配送订单退款';
|
||||
|
||||
break;
|
||||
case 12:
|
||||
|
||||
$text = '提现拒绝';
|
||||
|
||||
break;
|
||||
|
||||
case 13:
|
||||
|
||||
$text = '土地配送订单退款';
|
||||
|
||||
break;
|
||||
|
||||
case 14:
|
||||
|
||||
$text = '土地配送订单收入';
|
||||
|
||||
break;
|
||||
|
||||
case 15://地主提现
|
||||
|
||||
$text = '提现';
|
||||
|
||||
break;
|
||||
case 16:
|
||||
|
||||
$text = '商城订单运费';
|
||||
|
||||
break;
|
||||
case 17:
|
||||
|
||||
$text = '商城订单运费退款';
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
$text = '';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-15 10:41
|
||||
* @功能说明:获取用户消费信息
|
||||
*/
|
||||
public function getUserCashData($user_id){
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
|
||||
$arr = [1,3,5,6,8,10,14,16];
|
||||
//总收入
|
||||
$total_cash = $this->where($where)->where('type','in',$arr)->sum('price');
|
||||
//退款
|
||||
$refund_cash= $this->where($where)->where('type','in',[2,4,9,11,13,17])->sum('price');
|
||||
|
||||
$data = [
|
||||
|
||||
'total_cash' => round($total_cash,2),
|
||||
|
||||
'refund_cash' => round($refund_cash,2),
|
||||
//余额
|
||||
'cash' => round($total_cash-$refund_cash,2),
|
||||
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-28 14:08
|
||||
* @功能说明:分销用户的消费状况
|
||||
*/
|
||||
public function resellerCashData($user_id){
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
|
||||
$arr = [1,3,8];
|
||||
//总收入
|
||||
$total_cash = $this->where($where)->where('type','in',$arr)->sum('price');
|
||||
//退款
|
||||
$refund_cash= $this->where($where)->where('type','in',[2,4,9])->sum('price');
|
||||
|
||||
$data = [
|
||||
|
||||
// 'total_cash' => round($total_cash,2),
|
||||
//
|
||||
// 'refund_cash' => round($refund_cash,2),
|
||||
//余额
|
||||
'order_price' => round($total_cash-$refund_cash,2),
|
||||
|
||||
];
|
||||
//查付款的订单笔数
|
||||
$list = [
|
||||
|
||||
'land_order' => new LandOrder(),
|
||||
|
||||
'claim_order'=> new ClaimOrder(),
|
||||
|
||||
'shop_order' => new ShopOrder(),
|
||||
];
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
|
||||
$dis[] = ['pay_type','>',1];
|
||||
|
||||
$num = 0;
|
||||
|
||||
foreach ($list as $k=>$value){
|
||||
|
||||
$num += $value->where($dis)->count();
|
||||
}
|
||||
|
||||
$data['order_count'] = $num;
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @功能说明:获取指定日期的余额
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-12 15:10
|
||||
*/
|
||||
public function getDayCash($farmer_id,$type=1,$date='',$start_time='',$end_time='',$cash_status=''){
|
||||
|
||||
if($type==1){
|
||||
|
||||
$where[] = ['farmer_id','=',$farmer_id];
|
||||
|
||||
}else{
|
||||
|
||||
$where[] = ['store_id','=',$farmer_id];
|
||||
|
||||
}
|
||||
|
||||
$where[] = ['role_type','=',$type];
|
||||
|
||||
if(!empty($date)){
|
||||
|
||||
$date = strtotime($date)+86399;
|
||||
|
||||
$where[] = ['create_time','<',$date];
|
||||
|
||||
}elseif (!empty($start_time)&&!empty($end_time)){
|
||||
|
||||
$where[] = ['create_time','between',"$start_time,$end_time"];
|
||||
|
||||
}
|
||||
|
||||
if(!empty($cash_status)){
|
||||
|
||||
$where[] = ['cash_status','=',$cash_status];
|
||||
|
||||
}
|
||||
|
||||
$arr = [1,3,5,6,8,10,14,16];
|
||||
//总收入
|
||||
$total_cash = $this->where($where)->where('type','in',$arr)->sum('price');
|
||||
//退款
|
||||
$refund_cash= $this->where($where)->where('type','in',[2,4,9,11,13,17])->sum('price');
|
||||
//提现
|
||||
$wallet_cash= $this->where($where)->where('type','in',[7])->sum('price');
|
||||
|
||||
$wallet_refund_cash= $this->where($where)->where('type','in',[12])->sum('price');
|
||||
|
||||
$wallet_cash-=$wallet_refund_cash;
|
||||
|
||||
$data = [
|
||||
|
||||
'total_cash' => round($total_cash,2),
|
||||
|
||||
'refund_cash' => round($refund_cash,2),
|
||||
|
||||
'wallet_cash' => round($wallet_cash,2),
|
||||
|
||||
'income_cash' => round($total_cash-$refund_cash,2),
|
||||
//余额
|
||||
'cash' => round($total_cash-$refund_cash-$wallet_cash,2),
|
||||
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-12 16:28
|
||||
* @功能说明:获取指定日期的流水详情
|
||||
*/
|
||||
//1认养 2认养退款 3土地 4土地退款 5养殖 6养殖管理 7提现 8商城 9商城退款 10 配送订单 11配送退款 12 拒绝提现 13土地配送订单退款 14土地配送订单 16商城订单运费 17 商城订单运费退款
|
||||
public function getDateList($farmer_id,$date,$type=1,$cash_status=2){
|
||||
|
||||
if($type==1){
|
||||
|
||||
$dis = [
|
||||
|
||||
'farmer_id' => $farmer_id
|
||||
];
|
||||
|
||||
$arr = [
|
||||
|
||||
1 => 'claim_cash',
|
||||
|
||||
3 => 'land_cash',
|
||||
|
||||
7 => 'wallet_cash',
|
||||
|
||||
6 => 'breed_cash',
|
||||
|
||||
16 => 'shop_send_cash',
|
||||
|
||||
10 => 'claim_send_cash',
|
||||
|
||||
14 => 'land_send_cash',
|
||||
|
||||
11 => 'claim_send_refund_cash',
|
||||
|
||||
13 => 'land_send_refund_cash',
|
||||
|
||||
12 => 'wallet_refund_cash',
|
||||
|
||||
];
|
||||
}else{
|
||||
$arr = [
|
||||
|
||||
7 => 'wallet_cash',
|
||||
|
||||
8 => 'shop_cash',
|
||||
|
||||
9 => 'shop_refund_cash',
|
||||
|
||||
12 => 'wallet_refund_cash',
|
||||
|
||||
|
||||
];
|
||||
|
||||
$dis = [
|
||||
|
||||
'store_id' => $farmer_id
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$dis['role_type'] = $type;
|
||||
|
||||
if(!empty($date)){
|
||||
|
||||
$dis['create_date'] = $date;
|
||||
|
||||
}
|
||||
|
||||
if(!empty($cash_status)){
|
||||
|
||||
$dis['cash_status'] = $cash_status;
|
||||
|
||||
}
|
||||
|
||||
foreach ($arr as $key=>$value){
|
||||
|
||||
$dis['type'] = $key;
|
||||
|
||||
$list[$value] = $this->where($dis)->sum('price');
|
||||
|
||||
}
|
||||
|
||||
if($type==1){
|
||||
|
||||
$list['claim_send_cash'] -= $list['claim_send_refund_cash'];
|
||||
|
||||
$list['land_send_cash'] -= $list['land_send_refund_cash'];
|
||||
}
|
||||
|
||||
$list['wallet_cash'] -= $list['wallet_refund_cash'];
|
||||
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-29 11:17
|
||||
* @功能说明:添加流水
|
||||
*/
|
||||
public function addWater($order_id,$type,$role_type=1,$cash_status=0){
|
||||
|
||||
$data = $this->getModel($type);
|
||||
|
||||
$order = $data['model']->dataInfo(['id'=>$order_id]);
|
||||
//查询店铺的用户id
|
||||
if($role_type==2&&!empty($order['store_id'])){
|
||||
|
||||
$farmer_model = new Farmer();
|
||||
|
||||
$landlord_id = $farmer_model->where(['id'=>$order['store_id']])->value('user_id');
|
||||
|
||||
}else{
|
||||
|
||||
$landlord_id = 0;
|
||||
}
|
||||
//商城订单需要减去运费
|
||||
if($type==8){
|
||||
|
||||
$order['pay_price'] -= $order['freight'];
|
||||
}
|
||||
//商城退款需要减去运费
|
||||
if($type==9){
|
||||
|
||||
$order['pay_price'] -= $order['car_price'];
|
||||
}
|
||||
//商城订单农场主获得运费
|
||||
if($type==16){
|
||||
|
||||
$order['pay_price'] = $order['freight'];
|
||||
}
|
||||
//商城退款农场主退运费
|
||||
if($type==17){
|
||||
|
||||
$order['pay_price'] = $order['car_price'];
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $order['uniacid'],
|
||||
|
||||
'user_id' => $order['user_id'],
|
||||
|
||||
'role_type' => $role_type,
|
||||
|
||||
'farmer_id' => !empty($order['farmer_id'])?$order['farmer_id']:0,
|
||||
|
||||
'landlord_id' => $landlord_id,
|
||||
|
||||
'store_id' => !empty($order['store_id'])?$order['store_id']:0,
|
||||
|
||||
'price' => $order['pay_price'],
|
||||
|
||||
'order_code' => $order['order_code'],
|
||||
|
||||
'cash_time' => !empty($order['cash_time'])?$order['cash_time']:0,
|
||||
|
||||
'cash_status' => $cash_status,
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'type' => $type,
|
||||
|
||||
'add' => $data['add'],
|
||||
|
||||
'create_time' => time(),
|
||||
|
||||
'create_date' => date('Y-m-d',time()),
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-08 16:25
|
||||
* @功能说明:资金到账
|
||||
*/
|
||||
public function cashArrival($farmer_id=0,$landlord_id=0,$id=0){
|
||||
|
||||
$dis[] = ['cash_status','=',1];
|
||||
|
||||
$dis[] = ['cash_time','<',time()];
|
||||
|
||||
$dis[] = ['price','<>',0];
|
||||
|
||||
if(!empty($farmer_id)){
|
||||
|
||||
$dis[] = ['farmer_id','=',$farmer_id];
|
||||
|
||||
}
|
||||
|
||||
if(!empty($landlord_id)){
|
||||
|
||||
$dis[] = ['landlord_id','=',$landlord_id];
|
||||
|
||||
}
|
||||
|
||||
if(!empty($id)){
|
||||
|
||||
$dis[] = ['id','=',$id];
|
||||
|
||||
}
|
||||
|
||||
$list = $this->where($dis)->select()->toArray();
|
||||
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
$farmer_model = new Farmer();
|
||||
|
||||
$water_model = new BalanceWater();
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$cash = $value['add']==1?$value['price']:$value['price']*-1;
|
||||
//农场主
|
||||
if($value['role_type']==1){
|
||||
|
||||
$farmer = $farmer_model->dataInfo(['id'=>$value['farmer_id']]);
|
||||
|
||||
if(!empty($farmer)){
|
||||
|
||||
$res = $farmer_model->dataUpdate(['id'=>$value['farmer_id'],'lock'=>$farmer['lock']],['cash'=>$farmer['cash']+$cash,'lock'=>$farmer['lock']+1]);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
//地主
|
||||
$order_data = [
|
||||
|
||||
'uniacid' => $value['uniacid'],
|
||||
|
||||
'user_id' => $value['landlord_id'],
|
||||
|
||||
'id' => $value['id'],
|
||||
|
||||
'pay_price'=> abs($cash),
|
||||
|
||||
];
|
||||
|
||||
switch ($value['type']){
|
||||
|
||||
case 8://商城订单
|
||||
|
||||
$water_type = 11;
|
||||
|
||||
$add = 1;
|
||||
|
||||
break;
|
||||
case 9://商城退款
|
||||
|
||||
$water_type = 10;
|
||||
|
||||
$add = 0;
|
||||
|
||||
break;
|
||||
case 12://拒绝提现
|
||||
|
||||
$water_type = 12;
|
||||
|
||||
$add = 1;
|
||||
|
||||
break;
|
||||
case 15://提现
|
||||
|
||||
$water_type = 8;
|
||||
|
||||
$add = 0;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$res = $water_model->addWater($order_data,$water_type,$add);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
//给当前店铺加减金额
|
||||
$farmer = $farmer_model->dataInfo(['id'=>$value['store_id']]);
|
||||
|
||||
if(!empty($farmer)){
|
||||
|
||||
$res = $farmer_model->dataUpdate(['id'=>$value['store_id'],'lock'=>$farmer['lock']],['cash'=>$farmer['cash']+$cash,'lock'=>$farmer['lock']+1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(isset($res)&&$res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$value['id'],'cash_status'=>1],['cash_status'=>2]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @功能说明:地主冻结金额
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 14:15
|
||||
*/
|
||||
public function landordFrozenCash($user_id){
|
||||
|
||||
$this->cashArrival(0,$user_id);
|
||||
|
||||
$dis[] = ['landlord_id','=',$user_id];
|
||||
|
||||
$dis[] = ['role_type','=',2];
|
||||
|
||||
$dis[] = ['cash_status','in',[0,1]];
|
||||
|
||||
$cash = $this->where($dis)->where('type','=',8)->sum('price');
|
||||
|
||||
$refund_cash = $this->where($dis)->where('type','=',9)->sum('price');
|
||||
|
||||
return round($cash-$refund_cash,2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-29 11:29
|
||||
* @功能说明:更具type获取模型
|
||||
*/
|
||||
public function getModel($type){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
|
||||
$data['model'] = new ClaimOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$data['model'] = new ClaimOrder();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$data['model'] = new LandOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
|
||||
$data['model'] = new BreedOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
|
||||
$data['model'] = new Wallet();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
|
||||
$data['model'] = new ShopOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
case 9:
|
||||
|
||||
$data['model'] = new ShopRefund();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
|
||||
case 10:
|
||||
//认养配送订单
|
||||
$data['model'] = new SendOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 11:
|
||||
//认养订单退款
|
||||
$data['model'] = new SendOrder();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
case 12:
|
||||
//拒绝提现
|
||||
$data['model'] = new Wallet();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
case 13:
|
||||
//土地订单退款
|
||||
$data['model'] = new SendOrder();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
case 14:
|
||||
//土地配送订单
|
||||
$data['model'] = new SendOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 15:
|
||||
//地主提现
|
||||
$data['model'] = new Wallet();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
case 16:
|
||||
//商城订单农场主获得运费
|
||||
$data['model'] = new ShopOrder();
|
||||
|
||||
$data['add'] = 1;
|
||||
|
||||
break;
|
||||
case 17:
|
||||
//商城订单农场主获得运费退款
|
||||
$data['model'] = new ShopRefund();
|
||||
|
||||
$data['add'] = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
126
app/farm/model/GoodsCate.php
Normal file
126
app/farm/model/GoodsCate.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class GoodsCate extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
//1商城 2土地 3认养
|
||||
protected $name = 'lbfarm_v2_goods_cate';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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,$cate){
|
||||
|
||||
$this->where(['goods_id'=>$id,'type'=>$type])->delete();
|
||||
|
||||
if(!empty($cate)){
|
||||
|
||||
foreach ($cate as $k=>$v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'cate_id' => $v,
|
||||
|
||||
'goods_id'=> $id,
|
||||
|
||||
'type' => $type
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-14 16:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventClaim($id,$data){
|
||||
|
||||
$this->addData($id,3,$data['uniacid'],$data['cate_id']);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
110
app/farm/model/InfoRecord.php
Normal file
110
app/farm/model/InfoRecord.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class InfoRecord extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_info_record';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 16:03
|
||||
* @功能说明:获取已读数量
|
||||
*/
|
||||
public function noReadCount($user_id,$uniacid){
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.user_id' => $user_id,
|
||||
|
||||
'b.status' => 1,
|
||||
|
||||
'b.type' => 3
|
||||
];
|
||||
|
||||
$read_count = $this->alias('a')
|
||||
->join('lbfarm_v2_welfare_column b','a.info_id = b.id')
|
||||
->where($dis)
|
||||
->count();
|
||||
|
||||
$info_model = new WelfareColumn();
|
||||
|
||||
$info_count = $info_model->where(['uniacid'=>$uniacid,'status'=>1,'type'=>3])->count();
|
||||
|
||||
return ($info_count - $read_count)>0?$info_count - $read_count:0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
195
app/farm/model/LandCate.php
Normal file
195
app/farm/model/LandCate.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandCate extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_cate';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'farmer_id'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取农场主
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-10 17:23
|
||||
*/
|
||||
public function getFarmerIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])&&!empty($data['type'])){
|
||||
|
||||
$text_model = new LandCateText();
|
||||
|
||||
$dis = [
|
||||
|
||||
'cate_id' => $data['id'],
|
||||
|
||||
'type' => $data['type']
|
||||
];
|
||||
|
||||
$list = $text_model->where($dis)->column('farmer_id');
|
||||
|
||||
return array_values($list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
if(isset($data['farmer_id'])){
|
||||
|
||||
$farmer_id = $data['farmer_id'];
|
||||
|
||||
unset($data['farmer_id']);
|
||||
|
||||
}
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($farmer_id)){
|
||||
|
||||
|
||||
$this->updateSome($id,$data['uniacid'],$farmer_id,$data['type']);
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(isset($data['farmer_id'])){
|
||||
|
||||
$farmer_id = $data['farmer_id'];
|
||||
|
||||
unset($data['farmer_id']);
|
||||
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($farmer_id)){
|
||||
|
||||
$this->updateSome($dis['id'],$data['uniacid'],$farmer_id,$data['type']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-10 17:15
|
||||
* @功能说明:
|
||||
*/
|
||||
public function updateSome($id,$uniacid,$data,$type){
|
||||
|
||||
$text_model = new LandCateText();
|
||||
|
||||
$text_model->where(['cate_id'=>$id,'type'=>$type])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'cate_id' => $id,
|
||||
|
||||
'farmer_id' => $v,
|
||||
|
||||
'type' => $type
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$text_model->saveAll($insert);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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-12-14 17:47
|
||||
* @功能说明:认养分类
|
||||
*/
|
||||
public function claimCateList($dis){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_land_cate_text b','a.id = b.cate_id')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->order('a.top desc.a.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
77
app/farm/model/LandCateText.php
Normal file
77
app/farm/model/LandCateText.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandCateText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_cate_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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
111
app/farm/model/LandCycle.php
Normal file
111
app/farm/model/LandCycle.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandCycle extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_cycle';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-10 17:15
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventLand($id,$uniacid,$data,$type){
|
||||
|
||||
$this->where(['uniacid'=>$uniacid])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$v = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'lande_id' => $id,
|
||||
|
||||
];
|
||||
|
||||
$this->insert($v);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
477
app/farm/model/LandList.php
Normal file
477
app/farm/model/LandList.php
Normal file
@@ -0,0 +1,477 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\GoodsCate;
|
||||
use app\shop\model\StoreGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandList extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_list';
|
||||
|
||||
protected $append = [
|
||||
|
||||
'min_price'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-12 16:10
|
||||
*/
|
||||
public function getCateIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$dis = [
|
||||
|
||||
'b.status' => 1,
|
||||
|
||||
'a.goods_id' => $data['id'],
|
||||
|
||||
'a.type' => 2,
|
||||
|
||||
'b.type' => 1,
|
||||
];
|
||||
|
||||
$goods_cate_model = new GoodsCate();
|
||||
|
||||
$list = $goods_cate_model->alias('a')
|
||||
->join('lbfarm_land_cate b','a.cate_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.title')
|
||||
->group('a.id')
|
||||
->order('a.id dsec')
|
||||
->column('b.id');
|
||||
|
||||
|
||||
return array_values($list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param $value
|
||||
// * @param $data
|
||||
// * @功能说明:
|
||||
// * @author chenniang
|
||||
// * @DataTime: 2022-01-26 15:16
|
||||
// */
|
||||
// public function getTextAttr($value,$data){
|
||||
//
|
||||
// if(!empty($value)){
|
||||
//
|
||||
//
|
||||
// return str_replace("&nbsp;","",getimgs($value));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-07 10:50
|
||||
* @功能说明:轮播图转格式
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-31 17:46
|
||||
* @功能说明:获取最低价格
|
||||
*/
|
||||
public function getMinPriceAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$spe_model = new LandSpe();
|
||||
|
||||
$price = $spe_model->where(['land_id'=>$data['id']])->min('price');
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$g_data = $data;
|
||||
|
||||
$arr = ['massif', 'seed', 'monitor','spe','cycle'];
|
||||
|
||||
foreach ($arr as $vs){
|
||||
|
||||
if(key_exists($vs,$data)){
|
||||
|
||||
unset($data[$vs]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($data['imgs'])){
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
}
|
||||
|
||||
if(!empty($data['cate_id'])){
|
||||
|
||||
$cate_id = $data['cate_id'];
|
||||
|
||||
unset($data['cate_id']);
|
||||
}
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$this->updateSome($id,$g_data,$cate_id,$data['uniacid']);
|
||||
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
$g_data = $data;
|
||||
|
||||
$arr = ['massif', 'seed', 'monitor','spe','cycle'];
|
||||
|
||||
foreach ($arr as $vs){
|
||||
|
||||
if(key_exists($vs,$data)){
|
||||
|
||||
unset($data[$vs]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!empty($data['imgs'])){
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
}
|
||||
|
||||
if(!empty($data['cate_id'])){
|
||||
|
||||
$cate_id = $data['cate_id'];
|
||||
|
||||
unset($data['cate_id']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
$this->updateSome($dis['id'],$g_data,$cate_id,$data['uniacid']);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-14 15:45
|
||||
* @功能说明:添加关联
|
||||
*/
|
||||
public function updateSome($id,$data,$cate,$uniacid){
|
||||
|
||||
$server = new \app\farm\server\Land();
|
||||
|
||||
$lan_text_model = new LandText();
|
||||
|
||||
$land_spe_model = new LandSpe();
|
||||
|
||||
$server->addObserver($lan_text_model);
|
||||
|
||||
$server->addObserver($land_spe_model);
|
||||
|
||||
$server->notify($id,$data);
|
||||
|
||||
$goods_cate_model = new GoodsCate();
|
||||
|
||||
$goods_cate_model->addData($id,2,$uniacid,$cate);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-20 14:00
|
||||
* @功能说明:前端土地列表
|
||||
*/
|
||||
public function indexDataList($dis,$alh,$sort=1){
|
||||
|
||||
switch ($sort){
|
||||
|
||||
case 1:
|
||||
$order = 'id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$order = 'distance asc,id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$order = 'sale_num desc,id desc';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$data = $this->where($dis)->field(['*',$alh])->order($order)->paginate(10)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-20 14:00
|
||||
* @功能说明:前端土地列表
|
||||
*/
|
||||
public function indexDataListV2($dis,$alh,$sort=1){
|
||||
|
||||
switch ($sort){
|
||||
|
||||
case 1:
|
||||
$order = 'a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
$order = 'distance asc,a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$order = 'a.sale_num desc,a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_cate b','a.id = b.goods_id','left')
|
||||
->where($dis)
|
||||
->field(['a.*',$alh])
|
||||
->group('a.id')
|
||||
->order($order)
|
||||
->paginate(10)
|
||||
->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-02-15 14:24
|
||||
* @功能说明:土地详情
|
||||
*/
|
||||
public function landInfo($dis){
|
||||
|
||||
$data = $this->dataInfo($dis);
|
||||
|
||||
$arr = [
|
||||
|
||||
1 => [
|
||||
'type_name'=>'massif',
|
||||
|
||||
'table' => new Massif()
|
||||
|
||||
],
|
||||
2 => [
|
||||
|
||||
'type_name'=> 'seed',
|
||||
|
||||
'table' => new Seed()
|
||||
|
||||
],
|
||||
4 => [
|
||||
'type_name'=> 'monitor',
|
||||
|
||||
'table' => new Monitor()
|
||||
|
||||
],
|
||||
5 => [
|
||||
|
||||
'type_name'=>'cycle',
|
||||
|
||||
]
|
||||
];
|
||||
|
||||
$source_model = new Source();
|
||||
|
||||
$land_text_model = new LandText();
|
||||
|
||||
foreach ($arr as $k=>$v){
|
||||
|
||||
if(empty($v['table'])){
|
||||
|
||||
$where = [
|
||||
|
||||
'land_id' => $data['id'],
|
||||
|
||||
'type' => $k,
|
||||
];
|
||||
|
||||
$obj = $land_text_model->where($where)->column('obj_id');
|
||||
|
||||
$data[$v['type_name']] = array_values($obj);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$where = [
|
||||
|
||||
'b.land_id' => $data['id'],
|
||||
|
||||
'b.type' => $k,
|
||||
|
||||
'a.status' => 1
|
||||
];
|
||||
|
||||
$obj = $v['table']->alias('a')
|
||||
->join('lbfarm_land_text b','b.obj_id = a.id','right')
|
||||
->where($where)
|
||||
->field('a.*,b.source_id as s_id')
|
||||
->group('a.id')
|
||||
->order('b.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if(!empty($obj)){
|
||||
|
||||
foreach ($obj as $key => &$value){
|
||||
|
||||
if(!empty($value['s_id'])){
|
||||
|
||||
$value['source_name'] = $source_model->where(['id'=>$value['s_id'],'status'=>1])->value('title');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data[$v['type_name']] = $obj;
|
||||
|
||||
}
|
||||
|
||||
$cate_model = new LandCate();
|
||||
|
||||
$data['cate_name'] = $cate_model->where(['id'=>$data['cate_id'],'status'=>1,'type'=>1])->value('title');
|
||||
|
||||
$land_spe = new LandSpe();
|
||||
//规格
|
||||
$data['spe'] = $land_spe->where(['land_id'=>$data['id']])->select()->toArray();
|
||||
|
||||
$mac_model = new Machine();
|
||||
|
||||
$data['machine_name'] = $mac_model->where(['id'=>$data['machine_id'],'status'=>1])->value('title');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-02 16:36
|
||||
* @功能说明:
|
||||
*/
|
||||
public function landSomeFind($id,$type){
|
||||
|
||||
$dis = [
|
||||
|
||||
'obj_id' => $id,
|
||||
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_land_text b','a.id = b.land_id')
|
||||
->where($dis)
|
||||
->where('a.status','>',-1)
|
||||
->find();
|
||||
|
||||
return !empty($data)?1:0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
677
app/farm/model/LandOrder.php
Normal file
677
app/farm/model/LandOrder.php
Normal file
@@ -0,0 +1,677 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\User;
|
||||
use app\farm\server\Land;
|
||||
use app\farm\model\BalanceWater;
|
||||
use app\shop\model\DistributionCash;
|
||||
use app\shop\model\IntegralLog;
|
||||
use app\publics\model\TmplConfig;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
use longbingcore\wxcore\WxTmpl;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandOrder extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_order';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-21 17:04
|
||||
* @功能说明:下单支付信息
|
||||
*/
|
||||
public function payOrderInfo($input){
|
||||
|
||||
$spe_model = new LandSpe();
|
||||
|
||||
$massif_model = new Massif();
|
||||
|
||||
$seed_model = new Seed();
|
||||
|
||||
$land_model = new LandList();
|
||||
|
||||
$text_model = new LandText();
|
||||
|
||||
$data['land'] = $land_model->dataInfo(['id'=>$input['land_id']]);
|
||||
|
||||
if(empty($data['land'])){
|
||||
|
||||
return ['code'=>500,'msg'=>'该土地已下架'];
|
||||
|
||||
}
|
||||
|
||||
$dis = [
|
||||
|
||||
'land_id' => $input['land_id'],
|
||||
|
||||
'spe_id' => $input['spe_id']
|
||||
];
|
||||
|
||||
$find = $this->where($dis)->where('pay_type','>=',1)->find();
|
||||
|
||||
if(!empty($find)){
|
||||
|
||||
return ['code'=>500,'msg'=>'该规格已被预约'];
|
||||
|
||||
}
|
||||
//规格
|
||||
$spe = $spe_model->dataInfo(['id'=>$input['spe_id']]);
|
||||
|
||||
if(empty($spe)){
|
||||
|
||||
return ['code'=>500,'msg'=>'该规格已下架'];
|
||||
}
|
||||
$data['spe'] = $spe;
|
||||
//地块
|
||||
$massif = $massif_model->dataInfo(['id'=>$input['massif_id']]);
|
||||
|
||||
if(empty($massif)){
|
||||
|
||||
return ['code'=>500,'msg'=>'该地块已下架'];
|
||||
}
|
||||
|
||||
$data['land_price'] = $spe['price'];
|
||||
|
||||
$data['cycle'] = $input['cycle'];
|
||||
|
||||
$data['total_massif_price'] = round($input['cycle']*$massif['price'],2);
|
||||
|
||||
$data['massif'] = $massif;
|
||||
|
||||
$data['seed_price'] = 0;
|
||||
|
||||
if(!empty($input['seed_data'])){
|
||||
|
||||
foreach ($input['seed_data'] as $v){
|
||||
|
||||
$seed = $seed_model->dataInfo(['id'=>$v['id']]);
|
||||
|
||||
if(empty($seed)){
|
||||
|
||||
return ['code'=>500,'msg'=>'该种子已下架'];
|
||||
}
|
||||
//溯源id
|
||||
$seed['source_id'] = $text_model->where(['land_id'=>$input['land_id'],'type'=>2,'obj_id'=>$v['id']])->value('source_id');
|
||||
|
||||
$seed['num'] = $v['num'];
|
||||
|
||||
$data['seed_price'] += $seed['seed_price']*$v['num'];
|
||||
|
||||
$data['seed'][] = $seed;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data['seed_price'] = round($data['seed_price'],2);
|
||||
//支付价格
|
||||
$data['pay_price'] = round($data['land_price']+$data['total_massif_price']+$data['seed_price'],2);
|
||||
|
||||
$pay_price = $data['init_price'] = $data['pay_price'];
|
||||
|
||||
if(!empty($input['coupon_id'])){
|
||||
|
||||
$coupon_record_model = new CouponRecord();
|
||||
|
||||
$coupon = $coupon_record_model->dataInfo(['id'=>$input['coupon_id'],'is_land'=>1,'status'=>1]);
|
||||
|
||||
if(!empty($coupon)&&$coupon['full']<=$data['pay_price']){
|
||||
|
||||
$data['pay_price'] -= $coupon['discount'];
|
||||
|
||||
}else{
|
||||
|
||||
$coupon = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data['land_price'] = $data['land_price']>0?$data['land_price']:0;
|
||||
|
||||
$data['land_price'] = round($data['land_price'],2);
|
||||
|
||||
$data['coupon_discount'] = !empty($coupon)?$coupon['discount']:0;
|
||||
|
||||
$data['coupon_discount'] = $data['coupon_discount']<$pay_price?$data['coupon_discount']:$pay_price;
|
||||
|
||||
$data['coupon_discount'] = round($data['coupon_discount'],2);
|
||||
|
||||
$data['coupon_id'] = !empty($coupon)?$coupon['id']:0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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: 2021-12-16 15:39
|
||||
* @功能说明:毁掉
|
||||
*/
|
||||
public function orderResult($order_code,$transaction_id){
|
||||
|
||||
$order = $this->dataInfo(['order_code'=>$order_code]);
|
||||
|
||||
if(!empty($order)&&$order['pay_type']==1){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_time' => time(),
|
||||
|
||||
'pay_type' => 2,
|
||||
|
||||
'transaction_id' => $transaction_id
|
||||
];
|
||||
|
||||
$this->dataUpdate(['id'=>$order['id']],$update);
|
||||
//扣除余额
|
||||
if($order['balance']>0){
|
||||
|
||||
$water_model = new \app\farm\model\BalanceWater();
|
||||
|
||||
$res = $water_model->addWater($order,6,0);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
}
|
||||
//添加流水
|
||||
$water_model = new FinanceWater();
|
||||
|
||||
$water_model->addWater($order['id'],3,1,1);
|
||||
//分销
|
||||
$cash_model = new DistributionCash();
|
||||
|
||||
$cash_model->addUserCash($order,2);
|
||||
|
||||
Db::commit();
|
||||
|
||||
$order['pay_time'] = $update['pay_time'];
|
||||
//发送订阅消息
|
||||
$this->paySendService($order);
|
||||
|
||||
$sys_model = new PushMsgModel($order['uniacid']);
|
||||
|
||||
$sys_model->sendMsg($order,5);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-27 19:19
|
||||
* @功能说明:发送订阅消息
|
||||
*/
|
||||
public function paySendService($order){
|
||||
|
||||
$user_model = new User();
|
||||
//获取用户的open_id
|
||||
$openid = $user_model->where(['id'=>$order['user_id']])->value('openid');
|
||||
//访问页面
|
||||
$page = 'land/pages/order/detail?id='.$order['id'].'¬ice=1';
|
||||
//模版消息model
|
||||
$tmpl_model = new TmplConfig();
|
||||
//获取模版
|
||||
$tmpl = $tmpl_model->where(['uniacid'=>$order['uniacid'],'tmpl_name'=>'land_order'])->find();
|
||||
//如果未添加模版消息 则不发送
|
||||
if(empty($tmpl)){
|
||||
return true;
|
||||
}else{
|
||||
$tmpl = $tmpl->toArray();
|
||||
}
|
||||
//模版id
|
||||
$tmpl_id = $tmpl['tmpl_id'];
|
||||
//模版类容
|
||||
$service_model = new WxTmpl($order['uniacid']);
|
||||
//模版的key
|
||||
$key_worlds = $service_model::getTmplKey($tmpl_id);
|
||||
|
||||
if(!empty($openid)&&!empty($tmpl_id)&&!empty($key_worlds)){
|
||||
//验证模版内容
|
||||
if(!is_array($key_worlds)||count($key_worlds)<4){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$seed_model = new LandOrderSeed();
|
||||
|
||||
$seed_name = $seed_model->where(['order_id'=>$order['id']])->column('title');
|
||||
|
||||
$seed_name = !empty($seed_name)?implode(',',$seed_name):'';
|
||||
|
||||
$order['goods_name'] = mb_substr($order['goods_name'],0,10);
|
||||
|
||||
$seed_name = mb_substr($seed_name,0,10);
|
||||
//发送内容
|
||||
$send_data = array(
|
||||
|
||||
$key_worlds[1]=>array(
|
||||
//商品名称
|
||||
'value'=> $order['order_code'],
|
||||
),
|
||||
$key_worlds[2]=>array(
|
||||
//种子明显
|
||||
'value'=> $order['goods_name'],
|
||||
),
|
||||
$key_worlds[3]=>array(
|
||||
//支付金额
|
||||
'value'=>!empty($seed_name)?$seed_name:'无',
|
||||
),
|
||||
$key_worlds[4]=>array(
|
||||
//商品价格
|
||||
'value'=>$order['pay_price'].'元',
|
||||
|
||||
),
|
||||
$key_worlds[5]=>array(
|
||||
//支付时间
|
||||
'value'=>date('Y-m-d H:i:s',$order['pay_time']),
|
||||
),
|
||||
);
|
||||
|
||||
// dump($send_data);exit;
|
||||
//模版消息库类
|
||||
$tmpl_sever = new WxTmpl($order['uniacid']);
|
||||
//发送模版消息
|
||||
$res = $tmpl_sever::sendTmpl($openid,$tmpl_id,$send_data,$page);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 10:13
|
||||
* @功能说明:超时自动退款
|
||||
*/
|
||||
public function autoCancelOrder($uniacid,$user_id=0){
|
||||
|
||||
$dis[] = ['uniacid','=',$uniacid];
|
||||
|
||||
$dis[] = ['pay_type','=',1];
|
||||
|
||||
$dis[] = ['over_time','<',time()];
|
||||
|
||||
if(!empty($user_id)){
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
}
|
||||
|
||||
$order = $this->where($dis)->select()->toArray();
|
||||
|
||||
if(!empty($order)){
|
||||
|
||||
foreach ($order as $value){
|
||||
|
||||
$this->cancelOrder($value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 10:13
|
||||
* @功能说明:退款
|
||||
*/
|
||||
public function cancelOrder($order){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$order['id'],'pay_type'=>1],['pay_type'=>-1]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'取消失败'];
|
||||
}
|
||||
|
||||
$land_model = new LandList();
|
||||
|
||||
$land_model->where(['id'=>$order['land_id']])->update(['sale_num'=>Db::Raw('sale_num-1')]);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-14 09:55
|
||||
* @功能说明:修改到期订单的状态
|
||||
*/
|
||||
public function orderInit($user_id=0){
|
||||
|
||||
$dis[] = ['pay_type','=',2];
|
||||
|
||||
$dis[] = ['end_time','<',time()];
|
||||
|
||||
if(!empty($user_id)){
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
}
|
||||
|
||||
$list = $this->where($dis)->select()->toArray();
|
||||
|
||||
$integral_model = new IntegralLog();
|
||||
|
||||
$distributionCash_model = new DistributionCash();
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_type' => 7
|
||||
];
|
||||
|
||||
$this->dataUpdate(['id'=>$value['id']],$update);
|
||||
//添加积分
|
||||
$integral_model->integralUserAdd($value['user_id'],$value['get_integral'],$value['uniacid'],2,4,$value['id'],0,$value);
|
||||
//分销
|
||||
$res = $distributionCash_model->cashArrival($value,2);
|
||||
|
||||
if($res==false){
|
||||
|
||||
Db::rollback();
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:后台下单列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 14:05
|
||||
*/
|
||||
public function adminDataList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_order_address b','a.id = b.order_id AND b.type=1','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.user_name,b.mobile')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dis
|
||||
* @param int $page
|
||||
* @功能说明:后台下单列表
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 14:05
|
||||
*/
|
||||
public function adminDataSelect($dis){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_order_address b','a.id = b.order_id AND b.type=1','left')
|
||||
->where($dis)
|
||||
->field('a.*,b.user_name,b.mobile')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-28 15:05
|
||||
* @功能说明:添加商品时溯源下拉框
|
||||
*/
|
||||
public function goodsSourceSelect($user_id){
|
||||
|
||||
$dis[] = ['a.user_id','=',$user_id];
|
||||
|
||||
$dis[] = ['a.pay_type','>',1];
|
||||
|
||||
$order_source = $this->alias('a')
|
||||
->join('lbfarm_land_order_seed b','a.id = b.order_id')
|
||||
->where($dis)
|
||||
->column('source_id');
|
||||
|
||||
$source_model = new Source();
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
|
||||
$where[] = ['status','in',[2,3]];
|
||||
|
||||
$where[] = ['type','=',1];
|
||||
|
||||
$farmer_model = new Farmer();
|
||||
//如果自己是农场主
|
||||
$farmer_id = $farmer_model->where($where)->value('id');
|
||||
|
||||
if(!empty($farmer_id)){
|
||||
|
||||
$dis = [
|
||||
|
||||
'farmer_id' => $farmer_id,
|
||||
|
||||
'status' => 1
|
||||
|
||||
];
|
||||
|
||||
$source = $source_model->where($dis)->column('id');
|
||||
|
||||
$order_source = array_merge($order_source,$source);
|
||||
}
|
||||
|
||||
return $order_source;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-09 17:45
|
||||
* @功能说明:土地到期提醒
|
||||
*/
|
||||
public function landOverService($uniacid){
|
||||
//模版消息model
|
||||
$tmpl_model = new TmplConfig();
|
||||
//获取模版
|
||||
$tmpl = $tmpl_model->dataInfo(['uniacid'=>$uniacid,'tmpl_name'=>'land_over']);
|
||||
|
||||
$push_model = new PushMsgModel($uniacid);
|
||||
|
||||
$dis[] = ['pay_type','>',1];
|
||||
|
||||
$dis[] = ['have_notice','=',0];
|
||||
|
||||
$dis[] = ['end_time','<',time()+10*86400];
|
||||
|
||||
$list = $this->where($dis)->select()->toArray();
|
||||
|
||||
if(!empty($list)){
|
||||
|
||||
foreach ($list as $value){
|
||||
|
||||
$this->dataUpdate(['id'=>$value['id']],['have_notice'=>1]);
|
||||
|
||||
if(!empty($tmpl)){
|
||||
|
||||
$this->overService($value,$tmpl);
|
||||
}
|
||||
|
||||
$push_model->sendMsg($value,9);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-27 19:19
|
||||
* @功能说明:发送订阅消息
|
||||
*/
|
||||
public function overService($order,$tmpl){
|
||||
|
||||
$this->dataUpdate(['id'=>$order['id']],['have_notice'=>1]);
|
||||
|
||||
$user_model = new User();
|
||||
//获取用户的open_id
|
||||
$openid = $user_model->where(['id'=>$order['user_id']])->value('openid');
|
||||
//访问页面
|
||||
$page = 'land/pages/order/detail?id='.$order['id'].'¬ice=1';
|
||||
//模版id
|
||||
$tmpl_id = $tmpl['tmpl_id'];
|
||||
//模版类容
|
||||
$service_model = new WxTmpl($order['uniacid']);
|
||||
//模版的key
|
||||
$key_worlds = $service_model::getTmplKey($tmpl_id);
|
||||
|
||||
if(!empty($openid)&&!empty($tmpl_id)&&!empty($key_worlds)){
|
||||
//验证模版内容
|
||||
if(!is_array($key_worlds)||count($key_worlds)<4){
|
||||
|
||||
return true;
|
||||
}
|
||||
//发送内容
|
||||
$send_data = array(
|
||||
|
||||
$key_worlds[1]=>array(
|
||||
//商品名称
|
||||
'value'=> $order['goods_name'],
|
||||
),
|
||||
$key_worlds[2]=>array(
|
||||
//到期时间
|
||||
'value'=> date('Y-m-d H:i',$order['end_time']),
|
||||
),
|
||||
$key_worlds[3]=>array(
|
||||
//商品价格
|
||||
'value'=>$order['order_code'],
|
||||
),
|
||||
$key_worlds[4]=>array(
|
||||
//支付金额
|
||||
'value'=> '你的土地将到期,请注意管理',
|
||||
)
|
||||
);
|
||||
//模版消息库类
|
||||
$tmpl_sever = new WxTmpl($order['uniacid']);
|
||||
//发送模版消息
|
||||
$res = $tmpl_sever::sendTmpl($openid,$tmpl_id,$send_data,$page);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
272
app/farm/model/LandOrderSeed.php
Normal file
272
app/farm/model/LandOrderSeed.php
Normal file
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandOrderSeed extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_order_seed';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'source',
|
||||
|
||||
'total_weight',
|
||||
|
||||
'send_tmpl_id'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-04 14:14
|
||||
* @功能说明:获取配送模版id
|
||||
*/
|
||||
public function getSendTmplIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['seed_id'])){
|
||||
|
||||
$seed_model = new Seed();
|
||||
|
||||
$id = $seed_model->where(['id'=>$data['seed_id']])->value('send_tmpl_id');
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:总重量
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-04 11:23
|
||||
*/
|
||||
public function getTotalWeightAttr($value,$data){
|
||||
|
||||
if(isset($data['output_value'])&&isset($data['area'])){
|
||||
|
||||
return round($data['output_value']*$data['area'],2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-14 10:11
|
||||
* @功能说明:溯源
|
||||
*/
|
||||
public function getSourceAttr($value,$data){
|
||||
|
||||
if(!empty($data['source_id'])){
|
||||
|
||||
$source_model = new Source();
|
||||
|
||||
$source = $source_model->dataInfo(['id'=>$data['source_id']]);
|
||||
|
||||
return $source;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-21 16:52
|
||||
* @功能说明:添加订单种子
|
||||
*/
|
||||
public function orderSeedAdd($data,$order_id){
|
||||
|
||||
$seed_model = new Seed();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $v){
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $v['uniacid'],
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'title' => $v['title'],
|
||||
|
||||
'imgs' => !empty($v['imgs'][0])?$v['imgs'][0]:'',
|
||||
|
||||
'output_value' => $v['output_value'],
|
||||
|
||||
'month' => implode(',',$v['month']),
|
||||
|
||||
'area' => $v['area'],
|
||||
|
||||
'grow_cycle' => $v['grow_cycle'],
|
||||
|
||||
'picking_cycle'=> $v['picking_cycle'],
|
||||
|
||||
'seed_cycle' => $v['seed_cycle'],
|
||||
|
||||
'seed_price' => $v['seed_price'],
|
||||
|
||||
'num' => $v['num'],
|
||||
|
||||
'seed_id' => $v['id'],
|
||||
|
||||
'source_id' => $v['source_id'],
|
||||
|
||||
'total_price' => round($v['num']*$v['seed_price'],2),
|
||||
|
||||
];
|
||||
|
||||
$this->insert($insert);
|
||||
|
||||
$seed_model->updateSaleNum($v['id'],$v['num']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-04 14:00
|
||||
* @功能说明:获取配送飞
|
||||
*/
|
||||
public function getSendPrice($address_id,$order_id,$times=0){
|
||||
|
||||
if($times>0){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$list = $this->where(['order_id'=>$order_id])->field('*,num as goods_num')->select()->toArray();
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$price = $config_model->getTotalSendPrice($address_id,$list,2);
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page=10){
|
||||
|
||||
$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-12-16 15:39
|
||||
* @功能说明:毁掉
|
||||
*/
|
||||
public function orderResult($order_code,$transaction_id){
|
||||
|
||||
$order = $this->dataInfo(['order_code'=>$order_code]);
|
||||
|
||||
if(!empty($order)&&$order['pay_type']==1){
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_time' => time(),
|
||||
|
||||
'pay_type' => 2,
|
||||
|
||||
'transaction_id' => $transaction_id
|
||||
];
|
||||
|
||||
$this->dataUpdate(['id'=>$order['id']],$update);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-11 16:02
|
||||
* @功能说明:订单种子
|
||||
*/
|
||||
public function orderSeed($order_id){
|
||||
|
||||
$data = $this->where(['order_id'=>$order_id])->select()->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
111
app/farm/model/LandSourceText.php
Normal file
111
app/farm/model/LandSourceText.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandSourceText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_source_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-12-14 16:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventClaim($id,$data){
|
||||
|
||||
$this->where(['obj_id'=>$id,'type'=>2])->delete();
|
||||
|
||||
if(!empty($data['source'])){
|
||||
|
||||
foreach ($data['source'] as $k => $v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'obj_id' => $id,
|
||||
|
||||
'source_id'=> $v,
|
||||
|
||||
'type' => 2
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
126
app/farm/model/LandSpe.php
Normal file
126
app/farm/model/LandSpe.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandSpe extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_spe';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-10 17:15
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventLand($id,$data){
|
||||
|
||||
$this->where(['land_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data['spe'])){
|
||||
|
||||
foreach ($data['spe'] as $k=>$v){
|
||||
|
||||
$v['uniacid'] = $data['uniacid'];
|
||||
|
||||
$v['land_id'] = $id;
|
||||
|
||||
$this->insert($v);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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-12-14 17:47
|
||||
* @功能说明:认养分类
|
||||
*/
|
||||
public function claimCateList($dis){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_land_cate_text b','a.id = b.cate_id')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->order('a.top desc.a.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
143
app/farm/model/LandText.php
Normal file
143
app/farm/model/LandText.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class LandText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_land_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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @功能说明:1地块服务 2关联种子 3关联溯源 4关联监控
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-20 15:48
|
||||
*/
|
||||
public function eventLand($id,$data){
|
||||
|
||||
$arr = [
|
||||
|
||||
1 => 'massif',
|
||||
|
||||
2 => 'seed',
|
||||
|
||||
// 3 => 'source',
|
||||
|
||||
4 => 'monitor',
|
||||
|
||||
5 => 'cycle'
|
||||
];
|
||||
|
||||
foreach ($arr as $k=>$v){
|
||||
|
||||
if(key_exists($v,$data)){
|
||||
|
||||
$this->updateSome($id,$data['uniacid'],$data[$v],$k);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-10 17:15
|
||||
* @功能说明:1 地块服务 2关联种子 3关联溯源 4关联监控
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function updateSome($id,$uniacid,$data,$type){
|
||||
|
||||
$this->where(['uniacid'=>$uniacid,'type'=>$type,'land_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'land_id' => $id,
|
||||
|
||||
'obj_id' => $v,
|
||||
|
||||
'type' => $type,
|
||||
|
||||
// 'source_id' => $type==2?$v['source_id']:0,
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($insert);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
186
app/farm/model/Machine.php
Normal file
186
app/farm/model/Machine.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\server\Land;
|
||||
use longbingcore\wxcore\PospalApi;
|
||||
use think\facade\Db;
|
||||
|
||||
class Machine extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_machine';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'farmer_name'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-21 16:58
|
||||
* @功能说明:农场主名字
|
||||
*/
|
||||
public function getFarmerNameAttr($value,$data){
|
||||
|
||||
if(!empty($data['farmer_id'])){
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $data['farmer_id'],
|
||||
|
||||
];
|
||||
|
||||
$farmer_model = new Farmer();
|
||||
|
||||
$name = $farmer_model->where($dis)->where('status','in',[2,3])->value('title');
|
||||
|
||||
return $name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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('status desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis,$file='*'){
|
||||
|
||||
$data = $this->where($dis)->field($file)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-21 17:58
|
||||
* @功能说明:远程获取仪器的数据
|
||||
*/
|
||||
public function getDataInfo($land_id,$type=1){
|
||||
|
||||
$model = $type==1?new LandList():new Claim();
|
||||
|
||||
$id = $model->where(['id'=>$land_id])->value('machine_id');
|
||||
|
||||
$data = $this->dataInfo(['id'=>$id]);
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$mac_model = new PospalApi();
|
||||
|
||||
$room = $mac_model->getRoomInfo($data['room_id']);
|
||||
|
||||
if($room['result']!='success'){
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$server_time = $room['server_time'];
|
||||
|
||||
foreach ($room['channel'] as $key=>$value){
|
||||
|
||||
if(is_string($value)&&strpos($key,'field') !== false){
|
||||
|
||||
$arr[$key]['field'] = $key;
|
||||
|
||||
$arr[$key]['text'] = $value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$last_value = json_decode($room['channel']['last_values'],true);
|
||||
|
||||
if(!empty($arr)){
|
||||
|
||||
foreach ($arr as $k=>$v){
|
||||
|
||||
$arr[$k]['value'] = isset($last_value[$v['field']])?$last_value[$v['field']]['value']:'';
|
||||
}
|
||||
}
|
||||
|
||||
$list['server_time'] = $server_time;
|
||||
|
||||
$list['data'] = array_values(array_values($arr));
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
164
app/farm/model/Massif.php
Normal file
164
app/farm/model/Massif.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Massif extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_massif_list';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'service'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-30 14:18
|
||||
* @功能说明:服务类型
|
||||
*/
|
||||
public function getServiceAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$service_model = new MassifService();
|
||||
|
||||
$list = $service_model->where(['massif_id'=>$data['id']])->select()->toArray();
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(!empty($data['service'])){
|
||||
|
||||
$service = $data['service'];
|
||||
|
||||
unset($data['service']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(!empty($service)){
|
||||
|
||||
$this->updateSome($id,$service,$data['uniacid']);
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-20 16:38
|
||||
* @功能说明:
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$service_model = new MassifService();
|
||||
|
||||
$service_model->where(['massif_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $v){
|
||||
|
||||
$v['massif_id'] = $id;
|
||||
|
||||
$v['uniacid'] = $uniacid;
|
||||
|
||||
$service_model->insert($v);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(!empty($data['service'])){
|
||||
|
||||
$service = $data['service'];
|
||||
|
||||
unset($data['service']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(!empty($service)){
|
||||
|
||||
$this->updateSome($dis['id'],$service,$data['uniacid']);
|
||||
|
||||
}
|
||||
|
||||
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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
76
app/farm/model/MassifService.php
Normal file
76
app/farm/model/MassifService.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class MassifService extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_massif_service';
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
166
app/farm/model/Monitor.php
Normal file
166
app/farm/model/Monitor.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use longbingcore\wxcore\YsCloudApi;
|
||||
use think\facade\Db;
|
||||
|
||||
class Monitor extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_monitor';
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-14 16:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventClaim($id,$data){
|
||||
|
||||
$this->where(['obj_id'=>$id,'type'=>2])->delete();
|
||||
|
||||
if(!empty($data['monitor'])){
|
||||
|
||||
foreach ($data['monitor'] as $k => $v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'obj_id' => $id,
|
||||
|
||||
'monitor_id'=> $v,
|
||||
|
||||
'type' => 2
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-11 14:28
|
||||
* @功能说明:获取监控地址
|
||||
*/
|
||||
public function getVideoUrl($id){
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $id
|
||||
];
|
||||
|
||||
$data = $this->dataInfo($dis);
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->dataUpdate($dis,['iv'=>$data['iv']+1]);
|
||||
|
||||
$api = new YsCloudApi($data['uniacid']);
|
||||
|
||||
$url = $api->getVideoInfo($data['deviceSerial'],$data['channelNo']);
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-11 15:57
|
||||
* @功能说明:农场监控列表
|
||||
*/
|
||||
public function farmerMonitorList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_farmer b','a.farmer_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.address')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
110
app/farm/model/MonitorText.php
Normal file
110
app/farm/model/MonitorText.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class MonitorText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_monitor_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-12-14 16:07
|
||||
* @功能说明:
|
||||
*/
|
||||
public function eventClaim($id,$data){
|
||||
|
||||
$this->where(['obj_id'=>$id,'type'=>2])->delete();
|
||||
|
||||
if(!empty($data['monitor'])){
|
||||
|
||||
foreach ($data['monitor'] as $k => $v){
|
||||
|
||||
$insert[$k] = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'obj_id' => $id,
|
||||
|
||||
'monitor_id'=> $v,
|
||||
|
||||
'type' => 2
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($insert);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
92
app/farm/model/Node.php
Normal file
92
app/farm/model/Node.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Node extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_node';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
162
app/farm/model/OrderAddress.php
Normal file
162
app/farm/model/OrderAddress.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class OrderAddress extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_order_address';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-21 14:48
|
||||
* @功能说明:添加订单地址
|
||||
*/
|
||||
public function orderAddressAdd($address_id,$order_id,$send_type=2,$type=1,$address_data=[]){
|
||||
|
||||
$address_model = new Address();
|
||||
|
||||
if($send_type==2){
|
||||
|
||||
$address = $address_model->dataInfo(['id'=>$address_id]);
|
||||
|
||||
}else{
|
||||
|
||||
$address = $address_data;
|
||||
|
||||
}
|
||||
|
||||
if(empty($address)){
|
||||
|
||||
return ['code'=>500,'msg'=>'地址未找到'];
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $address['uniacid'],
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'user_name'=> $address['user_name'],
|
||||
|
||||
'mobile' => $address['mobile'],
|
||||
|
||||
'province' => !empty($address['province'])?$address['province']:'',
|
||||
|
||||
'city' => !empty($address['city'])?$address['city']:'',
|
||||
|
||||
'area' => !empty($address['area'])?$address['city']:'',
|
||||
|
||||
'lng' => !empty($address['lng'])?$address['lng']:'',
|
||||
|
||||
'lat' => !empty($address['lat'])?$address['lat']:'',
|
||||
|
||||
'address' => !empty($address['address'])?$address['address']:'',
|
||||
|
||||
'address_info' => !empty($address['address_info'])?$address['address_info']:'',
|
||||
|
||||
'type' => $type,
|
||||
|
||||
'send_type'=> $send_type,
|
||||
|
||||
'address_id'=> $address_id,
|
||||
|
||||
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'下单失败'];
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
83
app/farm/model/PayConfig.php
Normal file
83
app/farm/model/PayConfig.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class PayConfig extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_pay_config';
|
||||
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
$this->dataAdd($dis);
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
}
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
152
app/farm/model/Role.php
Normal file
152
app/farm/model/Role.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Role extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_role';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(isset($data['node'])){
|
||||
|
||||
$node = $data['node'];
|
||||
|
||||
unset($data['node']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($node)){
|
||||
|
||||
$this->updateSome($node,$id,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-04 14:10
|
||||
* @功能说明:添加权限节点
|
||||
*/
|
||||
public function updateSome($data,$id,$uniacid){
|
||||
|
||||
$node_model = new Node();
|
||||
|
||||
$node_model->where(['role_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$data[$k]['uniacid'] = $uniacid;
|
||||
|
||||
$data[$k]['role_id'] = $id;
|
||||
|
||||
$data[$k]['auth'] = !empty($v['auth'])?implode(',',$v['auth']):'';
|
||||
|
||||
}
|
||||
|
||||
$node_model->saveAll($data);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(isset($data['node'])){
|
||||
|
||||
$node = $data['node'];
|
||||
|
||||
unset($data['node']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($node)){
|
||||
|
||||
$this->updateSome($node,$dis['id'],$data['uniacid']);
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:06
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function dataList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
323
app/farm/model/Seed.php
Normal file
323
app/farm/model/Seed.php
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Seed extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_seed';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'source_id'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-12 14:18
|
||||
* @功能说明:种子
|
||||
*/
|
||||
public function getSourceIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$source_model = new LandSourceText();
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.obj_id' => $data['id'],
|
||||
|
||||
'type' => 1
|
||||
];
|
||||
|
||||
$list = $source_model->alias('a')
|
||||
->join('lbfarm_source b','b.id = a.source_id')
|
||||
->where($dis)
|
||||
->field('a.*,b.title')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-07 10:08
|
||||
* @功能说明:月份
|
||||
*/
|
||||
public function getMonthAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$month_model = new SeedMonth();
|
||||
|
||||
$list = $month_model->where(['seed_id'=>$data['id']])->column('month');
|
||||
|
||||
return array_values($list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-30 16:54
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['imgs'] = !empty($data['imgs'])?implode(',',$data['imgs']):'';
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(isset($data['month'])){
|
||||
|
||||
$month = $data['month'];
|
||||
|
||||
unset($data['month']);
|
||||
}
|
||||
|
||||
if(isset($data['source_id'])){
|
||||
|
||||
$source_id = $data['source_id'];
|
||||
|
||||
unset($data['source_id']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(isset($month)){
|
||||
|
||||
$this->updateSome($month,$id,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-07 10:03
|
||||
* @功能说明:添加种子月份
|
||||
*/
|
||||
public function updateSome($data,$id,$uniacid,$seed=[]){
|
||||
|
||||
$month_model = new SeedMonth();
|
||||
|
||||
$month_model->where(['seed_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
$season = ceil($v/3);
|
||||
|
||||
$insert[$k]=[
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'seed_id' => $id,
|
||||
|
||||
'month' => $v,
|
||||
|
||||
'season' => $season
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$month_model->saveAll($insert);
|
||||
}
|
||||
|
||||
$soruce_model = new LandSourceText();
|
||||
|
||||
$soruce_model->where(['obj_id'=>$id,'type'=>1])->delete();
|
||||
|
||||
if(!empty($seed)){
|
||||
|
||||
foreach ($seed as $key=>$value){
|
||||
|
||||
$insertdata[$key] = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'obj_id' => $id,
|
||||
|
||||
'source_id' => $value,
|
||||
|
||||
'type' => 1
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$soruce_model->saveAll($insertdata);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(isset($data['month'])){
|
||||
|
||||
$month = $data['month'];
|
||||
|
||||
unset($data['month']);
|
||||
}
|
||||
|
||||
if(isset($data['source_id'])){
|
||||
|
||||
$source_id = $data['source_id'];
|
||||
|
||||
unset($data['source_id']);
|
||||
}
|
||||
|
||||
if(!empty($data['imgs'])){
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(isset($month)){
|
||||
|
||||
$this->updateSome($month,$dis['id'],$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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-01-07 10:31
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function indexDataList($dis,$sort,$page = 10){
|
||||
|
||||
switch ($sort){
|
||||
|
||||
case 1:
|
||||
|
||||
$order = 'a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$order = 'a.sale_num desc,a.id desc';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_seed_month b','a.id = b.seed_id','left')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->order($order)
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 13:39
|
||||
* @功能说明:修改库存
|
||||
*/
|
||||
public function updateSaleNum($seed_id,$num,$type=1){
|
||||
//加销量
|
||||
if($type==1){
|
||||
|
||||
$res = $this->where(['id'=>$seed_id])->update(['sale_num'=>Db::Raw("sale_num+$num")]);
|
||||
|
||||
}else{
|
||||
|
||||
$res = $this->where(['id'=>$seed_id])->update(['sale_num'=>Db::Raw("sale_num-$num")]);
|
||||
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
91
app/farm/model/SeedMonth.php
Normal file
91
app/farm/model/SeedMonth.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SeedMonth extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_seed_month';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
83
app/farm/model/SendConfig.php
Normal file
83
app/farm/model/SendConfig.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SendConfig extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_send_time_config';
|
||||
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
$this->dataAdd($dis);
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
}
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
547
app/farm/model/SendOrder.php
Normal file
547
app/farm/model/SendOrder.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\farm\model\BalanceWater;
|
||||
|
||||
use app\farm\model\User;
|
||||
use app\shop\model\IntegralLog;
|
||||
use longbingcore\wxcore\PayModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SendOrder extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_send_order';
|
||||
|
||||
|
||||
/**
|
||||
* @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: 2021-12-14 15:45
|
||||
* @功能说明:添加关联
|
||||
*/
|
||||
public function updateSome($id,$data){
|
||||
|
||||
$server = new \app\farm\server\Claim();
|
||||
|
||||
$claim_text_model = new ClaimText();
|
||||
|
||||
$source_text_model= new LandSourceText();
|
||||
|
||||
$monitor_text_model= new MonitorText();
|
||||
|
||||
$server->addObserver($claim_text_model);
|
||||
|
||||
$server->addObserver($source_text_model);
|
||||
|
||||
$server->addObserver($monitor_text_model);
|
||||
|
||||
$server->notify($id,$data);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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: 2021-12-16 15:39
|
||||
* @功能说明:回调
|
||||
*/
|
||||
public function orderResult($order_code,$transaction_id){
|
||||
|
||||
$order = $this->dataInfo(['order_code'=>$order_code]);
|
||||
|
||||
if(!empty($order)&&$order['pay_type']==1){
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_time' => time(),
|
||||
|
||||
'pay_type' => 2,
|
||||
|
||||
'transaction_id' => $transaction_id
|
||||
];
|
||||
|
||||
$this->dataUpdate(['id'=>$order['id']],$update);
|
||||
//扣除余额
|
||||
if($order['balance']>0){
|
||||
|
||||
$water_model = new BalanceWater();
|
||||
|
||||
$type = $order['type']==1?3:9;
|
||||
|
||||
$res = $water_model->addWater($order,$type,0);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
}
|
||||
}
|
||||
//添加流水
|
||||
$water_model = new FinanceWater();
|
||||
//1认养 2土地
|
||||
$water_type = $order['type']==1?10:14;
|
||||
|
||||
$water_model->addWater($order['id'],$water_type,1,0);
|
||||
|
||||
$this->paySendMsg($order);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 09:51
|
||||
* @功能说明:公众号给农场主发送通知
|
||||
*/
|
||||
public function paySendMsg($order){
|
||||
|
||||
$uniacid = $order['uniacid'];
|
||||
|
||||
$x_config = longbingGetAppConfig($uniacid);
|
||||
|
||||
if(empty($x_config['gzh_appid'])||empty($x_config['gzh_tplid'])){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$farmer_model = new Farmer();
|
||||
|
||||
$user_id = $farmer_model->where(['id'=>$order['farmer_id']])->value('user_id');
|
||||
|
||||
if(empty($user_id)){
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$openid = $user_model->where(['id'=>$user_id])->value('openid');
|
||||
|
||||
$access_token = longbingGetAccessToken($uniacid);
|
||||
|
||||
$page =$order['type']==1?"claim/pages/order/detail?id=".$order['id']."&tab=2¬ice=1":"land/pages/order/detail?id=".$order['id']."&tab=2¬ice=1";
|
||||
//post地址
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token={$access_token}";
|
||||
|
||||
$data = [
|
||||
//用户小程序openid
|
||||
'touser' => $openid,
|
||||
|
||||
'mp_template_msg' => [
|
||||
//公众号appid
|
||||
'appid' => $x_config['gzh_appid'],
|
||||
|
||||
"url" => "http://weixin.qq.com/download",
|
||||
//公众号模版id
|
||||
'template_id' => $x_config['gzh_tplid'],
|
||||
|
||||
'miniprogram' => [
|
||||
//小程序appid
|
||||
'appid' => $x_config['appid'],
|
||||
//跳转小程序地址
|
||||
'page' => $page,
|
||||
],
|
||||
'data' => array(
|
||||
|
||||
// 'first' => array(
|
||||
//
|
||||
// 'value' => $store_name.'技师,您有一笔新的订单',
|
||||
//
|
||||
// 'color' => '#93c47d',
|
||||
// ),
|
||||
//服务名称
|
||||
'keyword1' => array(
|
||||
|
||||
'value' => $order['order_code'],
|
||||
|
||||
'color' => '#93c47d',
|
||||
),
|
||||
//下单人
|
||||
'keyword2' => array(
|
||||
//内容
|
||||
'value' => date('Y-m-d H:i',$order['start_time']).'~'.date('Y-m-d H:i',$order['end_time']),
|
||||
|
||||
'color' => '#0000ff',
|
||||
),
|
||||
'keyword3' => array(
|
||||
//内容
|
||||
'value' => $order['text'],
|
||||
|
||||
'color' => '#0000ff',
|
||||
)
|
||||
|
||||
)
|
||||
],
|
||||
];
|
||||
|
||||
$data = json_encode($data);
|
||||
|
||||
$tmp = [
|
||||
|
||||
'url' => $url,
|
||||
|
||||
'data' => $data,
|
||||
];
|
||||
$rest = lbCurlPost($tmp['url'], $tmp['data']);
|
||||
|
||||
$rest = json_decode($rest, true);
|
||||
|
||||
return $rest;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-09 13:45
|
||||
* @功能说明:订单收货
|
||||
*/
|
||||
public function sendOrderReceiving($order,$hx_user=0,$hx_admin=0,$hx_time=0){
|
||||
|
||||
$order_id = $order['id'];
|
||||
|
||||
$update = [
|
||||
|
||||
'pay_type' => 7,
|
||||
|
||||
'receiving_time' => !empty($hx_time)?$hx_time:time(),
|
||||
|
||||
'hx_user' => $hx_user,
|
||||
|
||||
'hx_admin' => $hx_admin
|
||||
];
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$order_id],$update);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'收货失败'];
|
||||
}
|
||||
|
||||
$water_model = new FinanceWater();
|
||||
|
||||
$water_type = $order['type']==1?10:14;
|
||||
|
||||
$dis = [
|
||||
|
||||
'type' => $water_type,
|
||||
|
||||
'order_id' => $order_id
|
||||
];
|
||||
//将流水记录修改为可提现状态
|
||||
$res = $water_model->dataUpdate($dis,['cash_status'=>1]);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'收货失败1'];
|
||||
}
|
||||
//暂时只执行认养配送的
|
||||
if($order['type']==1){
|
||||
|
||||
$order_model = $order['type']==1?new ClaimOrder():new LandOrder();
|
||||
//有可能是自提
|
||||
$order_model->dataUpdate(['id'=>$order['order_id']],['pay_type'=>3]);
|
||||
|
||||
$top_order = $order_model->dataInfo(['id'=>$order['order_id']]);
|
||||
|
||||
$count = $this->where(['order_id'=>$order['order_id'],'type'=>$order['type'],'pay_type'=>7])->count();
|
||||
|
||||
if($count>=$top_order['send_times']){
|
||||
|
||||
$order_model->dataUpdate(['id'=>$top_order['id']],['pay_type'=>7]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$i_type = $order['type']==1?8:9;
|
||||
|
||||
$integral_model = new IntegralLog();
|
||||
//赠送积分
|
||||
$integral_model->integralUserAdd($order['user_id'],$order['get_integral'],$order['uniacid'],2,$i_type,$order['id']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 10:13
|
||||
* @功能说明:超时自动退款
|
||||
*/
|
||||
public function autoCancelOrder($uniacid,$user_id=0){
|
||||
|
||||
$where[] = ['uniacid','=',$uniacid];
|
||||
|
||||
$where[] = ['pay_type','=',3];
|
||||
|
||||
$where[] = ['auto_receiving_time','<',time()];
|
||||
|
||||
if(!empty($user_id)){
|
||||
|
||||
$dis[] = ['user_id','=',$user_id];
|
||||
}
|
||||
|
||||
$order = $this->where($where)->select()->toArray();
|
||||
|
||||
if(!empty($order)){
|
||||
|
||||
foreach ($order as $value){
|
||||
|
||||
$this->sendOrderReceiving($value,0,0,$value['auto_receiving_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-01 10:13
|
||||
* @功能说明:退款
|
||||
*/
|
||||
public function cancelOrder($order){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$res = $this->dataUpdate(['id'=>$order['id'],'pay_type'=>1],['pay_type'=>-1,'cancel_time'=>time()]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'取消失败'];
|
||||
}
|
||||
|
||||
$claim_model = new Claim();
|
||||
|
||||
$claim = $claim_model->dataInfo(['id'=>$order['goods_id']]);
|
||||
//加销量减库存
|
||||
$update = [
|
||||
|
||||
'stock' => $claim['stock'] +1,
|
||||
|
||||
'sale_num' => $claim['sale_num']-1,
|
||||
|
||||
'lock' => $claim['lock']+1
|
||||
|
||||
];
|
||||
|
||||
$res = $claim_model->dataUpdate(['id'=>$claim['id'],'lock'=>$claim['lock']],$update);
|
||||
|
||||
if($res==0){
|
||||
|
||||
Db::rollback();
|
||||
|
||||
return ['code'=>500,'msg'=>'取消失败'];
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $order_id
|
||||
* @param $type 1认养 2土地
|
||||
* @功能说明:指定订单的配送订单
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-16 14:37
|
||||
*/
|
||||
public function orderSendOrder($order_id,$type=1,$page=10){
|
||||
|
||||
$dis[] = ['order_id','=',$order_id];
|
||||
|
||||
$dis[] = ['pay_time','>',0];
|
||||
|
||||
$dis[] = ['type','=',$type];
|
||||
|
||||
$send_order_model = new SendOrder();
|
||||
|
||||
$data = $send_order_model->dataList($dis,$page);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['time_text'] = date('Y-m-d H:i',$v['start_time']).'~'.date('H:i',$v['end_time']);
|
||||
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
|
||||
$v['pay_time'] = $v['pay_time']>0?date('Y-m-d H:i:s',$v['pay_time']):0;
|
||||
|
||||
$v['send_time'] = $v['send_time']>0?date('Y-m-d H:i:s',$v['send_time']):0;
|
||||
|
||||
$v['receiving_time'] = $v['receiving_time']>0?date('Y-m-d H:i:s',$v['receiving_time']):0;
|
||||
|
||||
$v['refund_time'] = $v['refund_time']>0?date('Y-m-d H:i:s',$v['refund_time']):0;
|
||||
}
|
||||
}
|
||||
$dis = [
|
||||
|
||||
'order_id' => $order_id,
|
||||
|
||||
'type' => $type
|
||||
];
|
||||
//已经申请的配送次数
|
||||
$data['send_count'] = $send_order_model->where($dis)->where('pay_type','>',1)->count();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $order
|
||||
* @功能说明:配送订单退款
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 10:47
|
||||
*/
|
||||
public function refundCash($send_order,$payConfig){
|
||||
|
||||
if($send_order['send_type']==1||$send_order['pay_price']<=0){
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if($send_order['pay_model']==1){
|
||||
|
||||
$response = orderRefundApi($payConfig,$send_order['pay_price'],$send_order['pay_price'],$send_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']:$send_order['order_code'];
|
||||
|
||||
$this->dataUpdate(['id'=>$send_order['id']],['refund_code'=>$response['out_refund_no']]);
|
||||
|
||||
}else {
|
||||
//失败就报错
|
||||
$discption = !empty($response['err_code_des'])?$response['err_code_des']:$response['return_msg'];
|
||||
|
||||
return ['code'=>500,'msg'=>$discption];
|
||||
|
||||
}
|
||||
|
||||
}elseif ($send_order['pay_model']==2){
|
||||
|
||||
$water_model = new BalanceWater();
|
||||
|
||||
$res = $water_model->addWater($send_order,4,1);
|
||||
|
||||
if($res==0){
|
||||
|
||||
return ['code'=>500,'msg'=>'退款失败2'];
|
||||
|
||||
}
|
||||
}else{
|
||||
//支付宝
|
||||
$pay_model = new PayModel($payConfig);
|
||||
|
||||
$res = $pay_model->aliRefund($send_order['transaction_id'],$send_order['pay_price']);
|
||||
|
||||
if(isset($res['alipay_trade_refund_response']['code'])&&$res['alipay_trade_refund_response']['code']==10000){
|
||||
|
||||
$this->dataUpdate(['id'=>$send_order['id']],['refund_code'=>$res['alipay_trade_refund_response']['out_trade_no']]);
|
||||
|
||||
}else{
|
||||
|
||||
return ['code'=>500,'msg'=> $res['alipay_trade_refund_response']['sub_msg']];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
602
app/farm/model/ShopGoods.php
Normal file
602
app/farm/model/ShopGoods.php
Normal file
@@ -0,0 +1,602 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\massage\model\GoodsSpe;
|
||||
use app\shop\model\GoodsSpePrice;
|
||||
use app\shop\model\IntegralGoods;
|
||||
use app\shop\model\SeckillGoods;
|
||||
use app\shop\model\StoreGoods;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopGoods extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_goods';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'show_price',
|
||||
|
||||
'show_init_price',
|
||||
|
||||
'all_stock',
|
||||
|
||||
'all_sale_count',
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取分类
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-13 17:28
|
||||
*/
|
||||
public function getCateIdAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$goods_cate_model = new GoodsCate();
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.type' => 1,
|
||||
|
||||
'a.goods_id' => $data['id'],
|
||||
|
||||
'b.status' => 1
|
||||
];
|
||||
|
||||
$list = $goods_cate_model->alias('a')
|
||||
->join('lbfarm_shop_goods_cate b','a.cate_id = b.id')
|
||||
->where($dis)
|
||||
->column('b.id');
|
||||
|
||||
return array_values($list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取分类
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-13 17:28
|
||||
*/
|
||||
public function getStoreAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$store_model = new StoreGoods();
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.type' => 1,
|
||||
|
||||
'a.goods_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)
|
||||
->column('b.id');
|
||||
|
||||
return array_values($list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public function getTextAttr($value,$data){
|
||||
//
|
||||
// if(!empty($value)){
|
||||
//
|
||||
// return @unserialize($value);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-11-02 14:08
|
||||
* @功能说明:虚拟销量+真实销量
|
||||
*/
|
||||
public function getAllSaleCountAttr($value,$data){
|
||||
|
||||
if(isset($data['sale_num'])&&isset($data['true_sale_num'])){
|
||||
|
||||
return $data['sale_num']+$data['true_sale_num'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 11:12
|
||||
*/
|
||||
public function getImgsAttr($value,$data){
|
||||
|
||||
if(!empty($value)){
|
||||
|
||||
return explode(',',$value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 15:13
|
||||
* @功能说明:获取商品的最低价格
|
||||
*/
|
||||
public function getShowPriceAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$list = $spe_model->where(['goods_id'=>$data['id']])->min('price');
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 15:13
|
||||
* @功能说明:获取商品的最低价格
|
||||
*/
|
||||
public function getShowInitPriceAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$list = $spe_model->where(['goods_id'=>$data['id']])->order('price,id desc')->value('original_price');
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 15:13
|
||||
* @功能说明:获取总库存
|
||||
*/
|
||||
public function getAllStockAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$list = $spe_model->where(['goods_id'=>$data['id']])->sum('stock');
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$cate_id = $data['cate_id'];
|
||||
|
||||
unset($data['cate_id']);
|
||||
|
||||
$store = $data['store'];
|
||||
|
||||
unset($data['store']);
|
||||
|
||||
unset($data['specsItem']);
|
||||
|
||||
unset($data['specsTable']);
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$this->updateSome($id,$data['uniacid'],$store,$cate_id);
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uniacid
|
||||
* @param $spe
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-23 13:35
|
||||
*/
|
||||
public function updateSome($id,$uniacid,$store,$cate){
|
||||
|
||||
$store_model = new StoreGoods();
|
||||
|
||||
$goods_cate_model = new GoodsCate();
|
||||
|
||||
$store_model->where(['type'=>1,'goods_id'=>$id])->delete();
|
||||
|
||||
$goods_cate_model->where(['type'=>1,'goods_id'=>$id])->delete();
|
||||
|
||||
if(!empty($store)){
|
||||
|
||||
foreach ($store as $ks=>$vs){
|
||||
|
||||
$insert[$ks] = [
|
||||
|
||||
'goods_id' => $id,
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'store_id' => $vs
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$store_model->saveAll($insert);
|
||||
}
|
||||
|
||||
if(!empty($cate)){
|
||||
|
||||
foreach ($cate as $ks=>$vs){
|
||||
|
||||
$inserts[$ks] = [
|
||||
|
||||
'goods_id' => $id,
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'cate_id' => $vs
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
$goods_cate_model->saveAll($inserts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function goodsUpdate($dis,$data){
|
||||
|
||||
$cate_id = $data['cate_id'];
|
||||
|
||||
unset($data['cate_id']);
|
||||
|
||||
$store = $data['store'];
|
||||
|
||||
unset($data['store']);
|
||||
|
||||
unset($data['specsItem']);
|
||||
|
||||
unset($data['specsTable']);
|
||||
|
||||
$data['imgs'] = implode(',',$data['imgs']);
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
$this->updateSome($dis['id'],$data['uniacid'],$store,$cate_id);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-04 11:44
|
||||
* @功能说明:
|
||||
*/
|
||||
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-13 17:03
|
||||
* @功能说明:商城列表
|
||||
*/
|
||||
public function goodsList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_store b','a.id = b.goods_id AND b.type=1','left')
|
||||
->join('lbfarm_v2_goods_cate c','a.id = c.goods_id AND c.type=1','left')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->order('a.top desc,a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-07-13 17:03
|
||||
* @功能说明:商城列表
|
||||
*/
|
||||
public function indexGoodsList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_store b','a.id = b.goods_id AND b.type=1')
|
||||
->join('lbfarm_v2_goods_cate c','a.id = c.goods_id AND c.type=1')
|
||||
->join('lbfarm_farmer d','b.store_id = d.id')
|
||||
->where($dis)
|
||||
->field('a.*,d.title as store_name,d.id as store_id,d.cover as store_cover')
|
||||
->group('a.id')
|
||||
->order('a.top desc,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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 10:07
|
||||
* @功能说明:增加|减少库存 增加|减少销量
|
||||
*/
|
||||
public function setOrDelStock($goods_id,$spe_id,$num,$type=1,$refund = 0,$integral_id=0,$kill_atv_id=0){
|
||||
|
||||
if(empty($goods_id)){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$spe_model = new GoodsSpePrice();
|
||||
|
||||
$goods_info = $this->dataInfo(['id'=>$goods_id]);
|
||||
|
||||
$spe_info = $spe_model->dataInfo(['id'=>$spe_id]);
|
||||
//退货
|
||||
if($type==1){
|
||||
|
||||
$update = [
|
||||
|
||||
'true_sale_num' => $goods_info['true_sale_num']-$num,
|
||||
|
||||
'lock' => $goods_info['lock']+1,
|
||||
|
||||
];
|
||||
//如果是售后增加退款数量
|
||||
if($refund==1){
|
||||
|
||||
$update['refund_num'] = $goods_info['refund_num']+$num;
|
||||
}
|
||||
//减销量 加退款数量
|
||||
$res = $this->where(['id'=>$goods_id,'lock'=>$goods_info['lock']])->update($update);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'提交失败'];
|
||||
}
|
||||
|
||||
//增加库存
|
||||
$res = $spe_model->where(['id'=>$spe_id,'lock'=>$spe_info['lock']])->update(['stock'=>$spe_info['stock']+$num,'lock'=>$goods_info['lock']+1]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'提交失败'];
|
||||
}
|
||||
//积分
|
||||
if(!empty($integral_id)){
|
||||
|
||||
$integral_goods_model = new IntegralGoods();
|
||||
|
||||
$integral_goods_model->updateAtvStock($integral_id,$goods_id,$spe_id,$num,2);
|
||||
|
||||
}
|
||||
//秒杀商品
|
||||
if(!empty($kill_atv_id)){
|
||||
|
||||
$kill_model = new SeckillGoods();
|
||||
|
||||
$kill_model->updateAtvStock($kill_atv_id,$goods_id,$spe_id,$num,2);
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
//增加销量
|
||||
$res = $this->where(['id'=>$goods_id,'lock'=>$goods_info['lock']])->update(['true_sale_num'=>$goods_info['true_sale_num']+$num,'lock'=>$goods_info['lock']+1]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'提交失败'];
|
||||
}
|
||||
|
||||
$now_stock = $spe_info['stock'] - $num;
|
||||
|
||||
if($now_stock<0){
|
||||
|
||||
return ['code'=>500,'msg'=>'库存不足'.$goods_info['goods_name']];
|
||||
|
||||
}
|
||||
//减少库存
|
||||
$res = $spe_model->where(['id'=>$spe_id,'lock'=>$spe_info['lock']])->update(['stock'=>$spe_info['stock']-$num,'lock'=>$goods_info['lock']+1]);
|
||||
|
||||
if($res!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'提交失败'];
|
||||
}
|
||||
//积分
|
||||
if(!empty($integral_id)){
|
||||
|
||||
$integral_goods_model = new IntegralGoods();
|
||||
|
||||
$res = $integral_goods_model->updateAtvStock($integral_id,$goods_id,$spe_id,$num);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
//秒杀商品
|
||||
if(!empty($kill_atv_id)){
|
||||
|
||||
$kill_model = new SeckillGoods();
|
||||
|
||||
$res = $kill_model->updateAtvStock($kill_atv_id,$goods_id,$spe_id,$num,1);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-08-25 17:19
|
||||
* @功能说明:
|
||||
*/
|
||||
public function saleIngCount($uniacid,$type=1){
|
||||
|
||||
$spe_price_model = new GoodsSpePrice();
|
||||
|
||||
$dis = [];
|
||||
|
||||
$dis[]= ['uniacid','=',$uniacid];
|
||||
|
||||
$sale_type = $type==2?0:1;
|
||||
|
||||
$sale_out_goods = $spe_price_model->getSellOut($uniacid,$sale_type);
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1:
|
||||
$dis[] = ['status','=',1];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$dis[] = ['status','>',-1];
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$dis[] = ['status','=',0];
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$dis[] = ['id','in',$sale_out_goods];
|
||||
|
||||
$data = $this->where($dis)->count();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
138
app/farm/model/ShopGoodsCate.php
Normal file
138
app/farm/model/ShopGoodsCate.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopGoodsCate extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_goods_cate';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'goods_num'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @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){
|
||||
|
||||
$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-21 15:51
|
||||
* @功能说明:获取商城分类信息
|
||||
*/
|
||||
public function shopCateList($uniacid,$store_id=0){
|
||||
|
||||
|
||||
$dis = [
|
||||
|
||||
'a.uniacid' => $uniacid,
|
||||
|
||||
'a.status' => 1,
|
||||
|
||||
];
|
||||
|
||||
if(!empty($store_id)){
|
||||
|
||||
$dis['b.store_id'] = $store_id;
|
||||
|
||||
$dis['b.type'] = 2;
|
||||
}
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('lbfarm_v2_goods_store b','a.id = b.goods_id','left')
|
||||
->where($dis)
|
||||
->field('a.*')
|
||||
->group('a.id')
|
||||
->order('a.top desc,a.id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
90
app/farm/model/ShopGoodsSpe.php
Normal file
90
app/farm/model/ShopGoodsSpe.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class ShopGoodsSpe extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_shop_goods_spe';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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('status 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-03-19 16:08
|
||||
* @功能说明:开启默认
|
||||
*/
|
||||
public function updateOne($id){
|
||||
|
||||
$user_id = $this->where(['id'=>$id])->value('user_id');
|
||||
|
||||
$res = $this->where(['user_id'=>$user_id])->where('id','<>',$id)->update(['status'=>0]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1181
app/farm/model/ShopOrder.php
Normal file
1181
app/farm/model/ShopOrder.php
Normal file
File diff suppressed because it is too large
Load Diff
284
app/farm/model/ShopOrderGoods.php
Normal file
284
app/farm/model/ShopOrderGoods.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
namespace app\farm\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,$address_id=0){
|
||||
|
||||
$goods_model = new ShopGoods();
|
||||
|
||||
$car_model = new Car();
|
||||
|
||||
$config_model= new Config();
|
||||
|
||||
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']];
|
||||
// }
|
||||
//
|
||||
// }
|
||||
if(!empty($address_id)){
|
||||
|
||||
$res = $config_model->getGoodsSendPrice($address_id,$v,2);
|
||||
|
||||
if(!empty($res['code'])){
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
//校验
|
||||
$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'],
|
||||
|
||||
'integral' => !empty($v['integral_id'])?$v['integral']:0,
|
||||
|
||||
'i_price' => !empty($v['integral_id'])?$v['i_price']:0,
|
||||
|
||||
'integral_id' => $v['integral_id'],
|
||||
|
||||
'kill_atv_id' => $v['kill_atv_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,0,$v['kill_atv_id']);
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
933
app/farm/model/ShopRefund.php
Normal file
933
app/farm/model/ShopRefund.php
Normal file
@@ -0,0 +1,933 @@
|
||||
<?php
|
||||
namespace app\farm\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 longbingcore\wxcore\PayModel;
|
||||
use longbingcore\wxcore\PushMsgModel;
|
||||
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,0,$v['kill_atv_id']);
|
||||
|
||||
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();
|
||||
|
||||
$sys_model = new PushMsgModel($refund_order['uniacid']);
|
||||
|
||||
$sys_model->sendMsg($refund_order,6);
|
||||
|
||||
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($pay_order['pay_model']==1){
|
||||
//微信退款
|
||||
$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];
|
||||
|
||||
}
|
||||
|
||||
}elseif($pay_order['pay_model']==2){
|
||||
|
||||
|
||||
$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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
//支付宝
|
||||
$pay_model = new PayModel($payConfig);
|
||||
|
||||
$res = $pay_model->aliRefund($pay_order['transaction_id'],$pay_order['pay_price']);
|
||||
|
||||
if(isset($res['alipay_trade_refund_response']['code'])&&$res['alipay_trade_refund_response']['code']==10000){
|
||||
|
||||
$this->dataUpdate(['id'=>$pay_order['id']],['out_refund_no'=>$res['alipay_trade_refund_response']['out_trade_no']]);
|
||||
|
||||
}else{
|
||||
|
||||
return ['code'=>500,'msg'=> $res['alipay_trade_refund_response']['sub_msg']];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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'];
|
||||
|
||||
$list[$k]['kill_atv_id'] = $order_goods['kill_atv_id'];
|
||||
|
||||
$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'],
|
||||
|
||||
'kill_atv_id' => $value['kill_atv_id'],
|
||||
|
||||
'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,$refund_user=0,$is_admin=0){
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $refund_id
|
||||
];
|
||||
|
||||
$refund_order = $this->dataInfo($dis);
|
||||
|
||||
if($refund_order['status']!=1){
|
||||
|
||||
return ['code'=>500,'msg'=>'退款状态错误'];
|
||||
|
||||
}
|
||||
|
||||
$update = [
|
||||
|
||||
'status' => 3,
|
||||
|
||||
'refund_time' => time(),
|
||||
|
||||
'refund_user' => $refund_user,
|
||||
|
||||
'refund_user_admin' => $is_admin
|
||||
|
||||
];
|
||||
|
||||
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/farm/model/ShopRefundGoods.php
Normal file
116
app/farm/model/ShopRefundGoods.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
namespace app\farm\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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
160
app/farm/model/Source.php
Normal file
160
app/farm/model/Source.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Source extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_source';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'stage'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-14 17:23
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getStageAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$source_text_model = new SourceText();
|
||||
|
||||
$list = $source_text_model->where(['source_id'=>$data['id']])->select()->toArray();
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
if(!empty($data['stage'])){
|
||||
|
||||
$stage= $data['stage'];
|
||||
|
||||
unset($data['stage']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
if(!empty($stage)){
|
||||
|
||||
$this->updateSome($id,$stage,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:05
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function dataUpdate($dis,$data){
|
||||
|
||||
if(!empty($data['stage'])){
|
||||
|
||||
$stage = $data['stage'];
|
||||
|
||||
unset($data['stage']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(!empty($stage)){
|
||||
|
||||
$this->updateSome($dis['id'],$stage,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-14 17:14
|
||||
* @功能说明:
|
||||
*/
|
||||
public function updateSome($id,$data,$uniacid){
|
||||
|
||||
$source_text_model = new SourceText();
|
||||
|
||||
$source_text_model->where(['source_id'=>$id])->delete();
|
||||
|
||||
if(!empty($data)){
|
||||
|
||||
foreach ($data as $v){
|
||||
|
||||
$v['uniacid'] = $uniacid;
|
||||
|
||||
$v['source_id'] = $id;
|
||||
|
||||
$source_text_model->insert($v);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
101
app/farm/model/SourceText.php
Normal file
101
app/farm/model/SourceText.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SourceText extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_source_text';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'time_text'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-12-31 11:00
|
||||
*/
|
||||
public function getTimeTextAttr($value,$data){
|
||||
|
||||
if(!empty($data['time'])){
|
||||
|
||||
return date('Y-m-d',$data['time']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
331
app/farm/model/SystemInfo.php
Normal file
331
app/farm/model/SystemInfo.php
Normal file
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class SystemInfo extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_system_info';
|
||||
|
||||
protected $append = [
|
||||
|
||||
'hours',
|
||||
|
||||
'day'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 17:05
|
||||
*/
|
||||
public function getDayAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return infoFriendTime($data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取时间
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 16:36
|
||||
*/
|
||||
public function getHoursAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return date('H:i:s',$data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @param string $order_code
|
||||
* @param string $goods_name
|
||||
* @功能说明:获取系统消息拼接信息
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 14:44
|
||||
*/
|
||||
public function returnMsg($type,$data){
|
||||
|
||||
switch ($type){
|
||||
|
||||
case 1://提现成功
|
||||
|
||||
$data['msg'] = '提现成功!'.$data['true_price'].'元已提现到您的支付宝,请到支付宝查收';
|
||||
|
||||
$data['title'] = '提现通知';
|
||||
|
||||
break;
|
||||
|
||||
case 2://提现失败
|
||||
|
||||
$data['msg'] = '提现失败!管理员拒绝您的提现申请';
|
||||
|
||||
$data['title'] = '提现通知';
|
||||
|
||||
break;
|
||||
|
||||
case 3://商城下单
|
||||
|
||||
$data['msg'] = '您下单的订单已支付成功,等待卖家发货';
|
||||
|
||||
$data['title'] = '商城订单下单成功通知';
|
||||
|
||||
break;
|
||||
|
||||
case 4://商场发货
|
||||
|
||||
$data['msg'] = '您购买的订单已发货,预计5个工作日内送达。如遇特殊情况,可联系客服查询物流情况';
|
||||
|
||||
$data['title'] = '商城订单发货通知';
|
||||
|
||||
break;
|
||||
|
||||
case 5://土地下单
|
||||
|
||||
$data['msg'] = '您购买的土地农作物订单已生效';
|
||||
|
||||
$data['title'] = '土地订单下单成功通知';
|
||||
|
||||
break;
|
||||
|
||||
case 6://商场退款
|
||||
|
||||
$data['msg'] = '您的订单已退款成功';
|
||||
|
||||
$data['title'] = '商城订单退货通知';
|
||||
|
||||
break;
|
||||
|
||||
case 7://认养到期可配送
|
||||
|
||||
$data['msg'] = '您下单的('.$data['goods_name'].'),快去发起配送请求吧';
|
||||
|
||||
$data['title'] = '认养订单配送通知';
|
||||
|
||||
break;
|
||||
|
||||
case 8://认养下单
|
||||
|
||||
$data['msg'] = '您下单的('.$data['goods_name'].'),已支付成功';
|
||||
|
||||
$data['title'] = '认养订单下单通知';
|
||||
|
||||
break;
|
||||
|
||||
case 9://土地到期
|
||||
|
||||
$data['msg'] = '您租赁的土地,租赁到期时间为'.$data['end_time'];
|
||||
|
||||
$data['title'] = '土地租赁到期通知';
|
||||
|
||||
break;
|
||||
|
||||
case 10://积分
|
||||
|
||||
$data['msg'] = '您通过消费获得'.$data['get_integral'].'积分';
|
||||
|
||||
$data['title'] = '积分变动提醒';
|
||||
|
||||
break;
|
||||
|
||||
case 11://兑换商品消耗积分
|
||||
|
||||
$data['msg'] = '您已成功兑换积分商品,消耗'.$data['integral'].'积分';
|
||||
|
||||
$data['title'] = '积分变动提醒';
|
||||
|
||||
break;
|
||||
case 12://抽奖消耗积分
|
||||
|
||||
$data['msg'] = '您今日参与第'.$data['times'].'次积分抽奖,消耗'.$data['integral'].'积分';
|
||||
|
||||
$data['title'] = '积分变动提醒';
|
||||
|
||||
break;
|
||||
case 13://签到获取积分
|
||||
|
||||
$data['msg'] = '您已连续签到'.$data['times'].'天,成功获得'.$data['integral'].'积分';
|
||||
|
||||
$data['title'] = '签到提醒';
|
||||
|
||||
break;
|
||||
|
||||
case 14://签到
|
||||
|
||||
$data['msg'] = '你今日还未签到,快去签到吧';
|
||||
|
||||
$data['title'] = '签到提醒';
|
||||
|
||||
break;
|
||||
case 15://秒杀
|
||||
|
||||
$data['msg'] = '您预约的秒杀活动还有2分钟即将开始';
|
||||
|
||||
$data['title'] = '秒杀提醒';
|
||||
|
||||
break;
|
||||
case 16://秒杀
|
||||
|
||||
$data['msg'] = '储值成功,恭喜您成为'.$data['member_title'].'会员';
|
||||
|
||||
$data['title'] = '充值提醒';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $type
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 14:46
|
||||
*/
|
||||
public function infoAdd($data,$type){
|
||||
|
||||
$arr = $this->returnMsg($type,$data);
|
||||
//商城订单需要获取第一个封面图
|
||||
if(in_array($type,[3,4,6])){
|
||||
|
||||
$data['goods_cover'] = !empty($data['order_goods'][0]['goods_cover'])?$data['order_goods'][0]['goods_cover']:'';
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $data['uniacid'],
|
||||
|
||||
'user_id' => $data['user_id'],
|
||||
|
||||
'order_code' => !empty($data['order_code'])?$data['order_code']:'',
|
||||
|
||||
'goods_cover'=> !empty($data['goods_cover'])?$data['goods_cover']:'',
|
||||
|
||||
'type' => $type,
|
||||
|
||||
'obj_id' => $data['id'],
|
||||
|
||||
'msg' => $arr['msg'],
|
||||
|
||||
'title' => $arr['title'],
|
||||
];
|
||||
|
||||
$res = $this->dataAdd($insert);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 17:29
|
||||
* @功能说明:用户是否有未读消息
|
||||
*/
|
||||
public function userHaveNews($user_id,$uniacid){
|
||||
|
||||
$record_model = new InfoRecord();
|
||||
|
||||
$operate_no_read_count = $record_model->noReadCount($user_id,$uniacid);
|
||||
|
||||
$where[] = ['uniacid','=',$uniacid];
|
||||
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
|
||||
$no_read_count = $this->where($where)->where(['status'=>0])->count();
|
||||
|
||||
return $operate_no_read_count>0||$no_read_count>0?1:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
140
app/farm/model/User.php
Normal file
140
app/farm/model/User.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use app\shop\model\Member;
|
||||
use think\facade\Db;
|
||||
|
||||
class User extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_user_list';
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'member_title'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-09 16:29
|
||||
*/
|
||||
public function getMemberTitleAttr($value,$data){
|
||||
|
||||
if(isset($data['member_level'])){
|
||||
|
||||
$level_model = new Member();
|
||||
|
||||
$title = $level_model->where(['id'=>$data['member_level']])->value('title');
|
||||
|
||||
return !empty($title)?$title:'';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:04
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function dataAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$data['create_date'] = date('Y-m-d',time());
|
||||
|
||||
$data['year'] = date('Y',time());
|
||||
|
||||
$data['month'] = date('m',time());
|
||||
|
||||
$data['week'] = date('W',time());
|
||||
|
||||
$data['status'] = 1;
|
||||
|
||||
$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,$mapor=[]){
|
||||
|
||||
$data = $this->where($dis)->where(function ($query) use ($mapor){
|
||||
$query->whereOr($mapor);
|
||||
})->order('id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-29 11:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function dataInfo($dis,$field='*'){
|
||||
|
||||
$data = $this->where($dis)->field($field)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-10-27 15:42
|
||||
* @功能说明:订单自提码
|
||||
*/
|
||||
public function orderQr($input,$uniacid){
|
||||
|
||||
$data = longbingCreateWxCode($uniacid,$input,$input['page']);
|
||||
|
||||
$data = transImagesOne($data ,['qr_path'] ,$uniacid);
|
||||
|
||||
$qr = $data['qr_path'];
|
||||
|
||||
return $qr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
227
app/farm/model/Wallet.php
Normal file
227
app/farm/model/Wallet.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Wallet extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_farmer_wallet';
|
||||
|
||||
protected $append = [
|
||||
|
||||
'service_cash',
|
||||
|
||||
'create_time_text'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-09 18:25
|
||||
*/
|
||||
public function getCreateTimeTextAttr($value,$data){
|
||||
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return date('Y-m-d H:i:s',$data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-04-09 09:28
|
||||
* @功能说明:手续费
|
||||
*/
|
||||
public function getServiceCashAttr($value,$data){
|
||||
|
||||
if(isset($data['pay_price'])&&isset($data['true_price'])){
|
||||
|
||||
return round($data['pay_price']-$data['true_price'],2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 14:33
|
||||
* @功能说明:
|
||||
*/
|
||||
public function datePrice($date,$uniacid,$cap_id,$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('true_cash');
|
||||
|
||||
return round($price,2);
|
||||
|
||||
}else{
|
||||
|
||||
$count = $this->where($dis)->count();
|
||||
|
||||
return $count;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-18 16:06
|
||||
* @功能说明:
|
||||
*/
|
||||
public function adminList($dis,$page=10){
|
||||
|
||||
$data = $this->alias('a')
|
||||
->join('massage_service_coach_list b','a.coach_id = b.id')
|
||||
->where($dis)
|
||||
->field('a.*,b.coach_name')
|
||||
->group('a.id')
|
||||
->order('a.id desc')
|
||||
->paginate($page)
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-30 14:36
|
||||
* @功能说明:团长提现
|
||||
*/
|
||||
public function capCash($cap_id,$status=2,$type=0){
|
||||
|
||||
$dis = [
|
||||
|
||||
|
||||
'coach_id' => $cap_id,
|
||||
|
||||
'status' => $status
|
||||
];
|
||||
|
||||
if(!empty($type)){
|
||||
|
||||
$dis['type'] = $type;
|
||||
}
|
||||
|
||||
$price = $this->where($dis)->sum('apply_price');
|
||||
|
||||
return round($price,2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-30 14:36
|
||||
* @功能说明:团长提现
|
||||
*/
|
||||
public function capCashCount($cap_id,$status=2){
|
||||
|
||||
$dis = [
|
||||
|
||||
|
||||
'cap_id' => $cap_id,
|
||||
|
||||
'status' => $status
|
||||
];
|
||||
|
||||
$count = $this->where($dis)->count();
|
||||
|
||||
return $count;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
140
app/farm/model/WelfareColumn.php
Normal file
140
app/farm/model/WelfareColumn.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
namespace app\farm\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class WelfareColumn extends BaseModel
|
||||
{
|
||||
//定义表名
|
||||
protected $name = 'lbfarm_v2_welfare_column';
|
||||
|
||||
|
||||
|
||||
protected $append = [
|
||||
|
||||
'create_time_text',
|
||||
|
||||
'hours',
|
||||
|
||||
'day'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 17:05
|
||||
*/
|
||||
public function getDayAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return infoFriendTime($data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @功能说明:获取时间
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 16:36
|
||||
*/
|
||||
public function getHoursAttr($value,$data){
|
||||
|
||||
if(!empty($data['create_time'])){
|
||||
|
||||
return date('H:i:s',$data['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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){
|
||||
|
||||
$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,$field='*'){
|
||||
|
||||
$data = $this->where($dis)->field($field)->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():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user