初始化代码

This commit is contained in:
2025-12-22 14:32:54 +08:00
parent e27ab90d9f
commit d02b31a8b9
1459 changed files with 240973 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\BaseController;
use think\App;
use app\farm\model\Admin as Model;
use think\facade\Db;
use think\facade\Lang;
use think\Response;
class Admin extends BaseController
{
protected $model;
protected $config_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Model();
}
/**
* @author chenniang
* @DataTime: 2021-03-11 13:53
* @功能说明:登陆
*/
public function login(){
// $input = $this->_input;
initLogin();
$input = json_decode( $this->request->getInput(), true );
//dump($input);exit;
$dis = [
// 'uniacid' => $this->_uniacid,
'username'=> $input['username']
];
$data = $this->model->dataInfo($dis);
if(empty($data)){
return $this->error('该用户不存在', 400);
}
if($data['passwd']!=checkPass($input['passwd'])){
return $this->error('密码错误', 400);
}
$result['user'] = $data;
$result['token'] = uuid();
if (empty($result['token'])) {
return $this->error('系统错误', 400);
}
//添加缓存数据
setUserForToken($result['token'], $data, 99999999);
return $this->success($result);
}
public function success ( $data, $code = 200 )
{
$result[ 'data' ] = $data;
$result[ 'code' ] = $code;
$result[ 'sign' ] = null;
//复杂的签名
// if(isset($this->_user['keys'])){
// $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data));
// }
//简单的签名
if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) );
return $this->response( $result, 'json', $code );
}
//返回错误数据
public function error ( $msg, $code = 400 )
{
$result[ 'error' ] = Lang::get($msg);
$result[ 'code' ] = $code;
return $this->response( $result, 'json', 200 );
}
/**
* 输出返回数据
* @access protected
* @param mixed $data 要返回的数据
* @param String $type 返回类型 JSON XML
* @param integer $code HTTP状态码
* @return Response
*/
protected function response ( $data, $type = 'json', $code = 200 )
{
return Response::create( $data, $type )->code( $code );
}
}

View File

@@ -0,0 +1,191 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\BalanceCard;
use app\farm\model\BalanceOrder;
use think\App;
use think\facade\Db;
class AdminBalance extends AdminRest
{
protected $model;
protected $order_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new BalanceCard();
$this->order_model = new BalanceOrder();
}
/**
* @author chenniang
* @DataTime: 2021-07-04 19:09
* @功能说明:储值充值卡列表
*/
public function cardList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['name'])){
$dis[] = ['title','like','%'.$input['name'].'%'];
}
$data = $this->model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:56
* @功能说明:添加充值卡
*/
public function cardAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$res = $this->model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:57
* @功能说明:编辑充值卡
*/
public function cardUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$res = $this->model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:59
* @功能说明:充值卡详情
*/
public function cardInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$res = $this->model->dataInfo($dis);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 19:09
* @功能说明:储值订单列表
*/
public function orderList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',1];
if(!empty($input['name'])){
$dis[] = ['title','like','%'.$input['name'].'%'];
}
if(!empty($input['order_code'])){
$dis[] = ['order_code','like','%'.$input['order_code'].'%'];
}
if(!empty($input['start_time'])){
$dis[] = ['pay_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$data = $this->order_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:59
* @功能说明:充值订单详情
*/
public function orderInfo(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$res = $this->order_model->dataInfo($dis);
return $this->success($res);
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\BalanceCard;
use app\farm\model\BalanceOrder;
use app\farm\model\Breed;
use app\farm\model\Farmer;
use app\farm\model\LandList;
use app\farm\model\Massif;
use app\farm\model\Source;
use app\farm\server\Land;
use think\App;
use think\facade\Db;
class AdminBreed extends AdminRest
{
protected $model;
protected $massif_model;
protected $land_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new BalanceCard();
$this->massif_model = new Massif();
$this->land_model = new LandList();
}
/**
* @author chenniang
* @DataTime: 2021-12-29 10:29
* @功能说明:养殖管理
*/
public function breedList(){
$input = $this->_param;
$breed_model = new Breed();
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.status','>',-1];
if(!empty($input['title'])){
$dis[] = ['a.title','like','%'.$input['title'].'%'];
}
if(!empty($input['farmer_id'])){
$dis[] = ['b.farmer_id','=',$input['farmer_id']];
$dis[] = ['b.type','=',5];
}
$data = $breed_model->breedList($dis,$input['limit']);
if(!empty($data['data'])){
$farmer_model = new Farmer();
foreach ($data['data'] as &$v){
$v['farmer_name'] = $farmer_model->where('id','in',$v['farmer_id'])->column('title');
$v['farmer_name'] = implode(',',$v['farmer_name']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-29 10:30
* @功能说明:添加养殖管理
*/
public function breedAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$breed_model = new Breed();
$res = $breed_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-29 10:34
* @功能说明:编辑养殖管理
*/
public function breedUpdate(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$dis = [
'id' => $input['id']
];
$breed_model = new Breed();
$res = $breed_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-29 10:34
* @功能说明:编辑养殖管理
*/
public function breedInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$breed_model = new Breed();
$res = $breed_model->dataInfo($dis);
return $this->success($res);
}
}

View File

@@ -0,0 +1,834 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\Claim;
use app\farm\model\ClaimCollage;
use app\farm\model\ClaimOrder;
use app\farm\model\ClaimText;
use app\farm\model\CollageJoin;
use app\farm\model\Config;
use app\farm\model\Farmer;
use app\farm\model\LandCate;
use app\farm\model\LandOrder;
use app\farm\model\LandOrderSeed;
use app\farm\model\Machine;
use app\farm\model\Monitor;
use app\farm\model\MonitorText;
use app\farm\model\OrderAddress;
use app\farm\model\SendOrder;
use app\farm\model\Source;
use app\farm\model\User;
use app\shop\model\FreightTemplate;
use think\App;
use app\farm\model\Config as Model;
use think\facade\Db;
class AdminClaim extends AdminRest
{
protected $model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Model();
}
/**
* @author chenniang
* @DataTime: 2021-12-10 17:10
* @功能说明:领地 认养分类列表
*/
public function claimCateList(){
$input = $this->_param;
$cate_model = new LandCate();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
$dis[] = ['type','=',$input['type']];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$data = $cate_model->dataList($dis,$input['limit']);
if(!empty($data['data'])){
$farmer_model = new Farmer();
foreach ($data['data'] as &$v){
$v['farmer_title'] = $farmer_model->where('id','in',$v['farmer_id'])->where(['status'=>2])->column('title');
$v['farmer_title'] = array_values($v['farmer_title']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 15:04
* @功能说明:配置详情
*/
public function claimCateInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$cate_model = new LandCate();
$data = $cate_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 15:04
* @功能说明:领地 认养分类编辑
*/
public function claimCateUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$cate_model = new LandCate();
$input['uniacid'] = $this->_uniacid;
$data = $cate_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-10 17:13
* @功能说明:领地 认养分类添加
*/
public function claimCateAdd(){
$input = $this->_input;
$cate_model = new LandCate();
$input['uniacid'] = $this->_uniacid;
$data = $cate_model->dataAdd($input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-28 11:26
* @功能说明:用户下单列表
*/
public function orderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}
if(!empty($input['order_code'])){
$dis[] = ['a.order_code','like','%'.$input['order_code'].'%'];
}
if(!empty($input['goods_name'])){
$dis[] = ['a.goods_name','like','%'.$input['goods_name'].'%'];
}
if(!empty($input['mobile'])){
$dis[] = ['b.mobile','like','%'.$input['mobile'].'%'];
}
if(!empty($input['farmer_id'])){
$dis[] = ['a.farmer_id','=',$input['farmer_id']];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$order_model = new ClaimOrder();
$farmer_model = new Farmer();
$user_model = new User();
$data = $order_model->adminDataList($dis,$input['limit']);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['farmer_info'] = $farmer_model->dataInfo(['id'=>$v['farmer_id']],'title');
$v['user_info'] = $user_model->dataInfo(['id'=>$v['user_id']]);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-28 11:52
* @功能说明:用户下单详情
*/
public function orderInfo(){
$input = $this->_param;
$farmer_model = new Farmer();
$source_model = new Source();
$dis = [
'id' => $input['id']
];
$order_model = new ClaimOrder();
$data = $order_model->dataInfo($dis);
$data['time_text'] = date('Y-m-d',$data['start_time']).'~'.date('Y-m-d',$data['end_time']);
//农场信息
$data['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['farmer_id']]);
//溯源信息
$data['source'] = $source_model->dataInfo(['id'=>$data['source_id']]);
$address_model = new OrderAddress();
$data['address_info'] = $address_model->dataInfo(['order_id'=>$input['id'],'type'=>2]);
if($data['is_collage']==1){
$collage_model = new CollageJoin();
$collage_info = $collage_model->dataInfo(['order_id'=>$input['id']]);
if(!empty($collage_info)){
$data['collage_status'] = $collage_info['status'];
$data['collage_discount_price'] = $data['init_price']-$collage_info['price'];
$data['collage_discount_price'] = $data['collage_discount_price']>0?$data['collage_discount_price']:0;
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-02-08 17:14
* @功能说明:配送订单列表
*/
public function userSendOrderList(){
$input = $this->_param;
$send_order_model = new SendOrder();
$data = $send_order_model->orderSendOrder($input['claim_order_id'],1,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-02-16 17:21
* @功能说明:配送订单列表
*/
public function sendOrderList(){
$input = $this->_param;
$send_order_model = new SendOrder();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['pay_time','>',0];
if(!empty($input['pay_type'])){
$dis[] = ['pay_type','=',$input['pay_type']];
}
if(!empty($input['type'])){
$dis[] = ['type','=',$input['type']];
}
if(!empty($input['send_type'])){
$dis[] = ['send_type','=',$input['send_type']];
}
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
$data = $send_order_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-02-09 14:00
* @功能说明:配送订单详情
*/
public function sendOrderInfo()
{
$input = $this->_param;
$send_order_model = new SendOrder();
$seed_model = new LandOrderSeed;
$farmer_model = new Farmer();
$send_order = $send_order_model->dataInfo(['id' => $input['id']]);
if($send_order['type']==1){
$order_model = new ClaimOrder();
$send_order['claim_order'] = $order_model->dataInfo(['id' => $send_order['order_id']]);
}else{
$order_model = new LandOrder();
$send_order['land_order'] = $order_model->dataInfo(['id' => $send_order['order_id']]);
//种子列表
$send_order['land_order']['seed'] = $seed_model->orderSeed($send_order['order_id']);
}
$send_order['farmer_info'] = $farmer_model->dataInfo(['id'=>$send_order['farmer_id']]);
return $this->success($send_order);
}
/**
* @author chenniang
* @DataTime: 2022-02-09 10:24
* @功能说明:配送订单收货
*/
public function sendOrderReceiving(){
$input = $this->_input;
$send_order_model = new SendOrder();
$send_order = $send_order_model->dataInfo(['id'=>$input['id']]);
if(empty($send_order)){
$this->errorMsg('订单未找到');
}
if($send_order['pay_type']!=2&&$send_order['send_type']==1){
$this->errorMsg('订单状态错误');
}
if($send_order['pay_type']!=3&&$send_order['send_type']==2){
$this->errorMsg('订单状态错误');
}
$res = $send_order_model->sendOrderReceiving($send_order);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2022-02-09 09:47
* @功能说明:发货订单发货
*/
public function sendOrderSend(){
$input = $this->_input;
$send_order_model = new SendOrder();
$send_order = $send_order_model->dataInfo(['id'=>$input['id']]);
if(empty($send_order)){
$this->errorMsg('订单未找到');
}
if($send_order['pay_type']!=2){
$this->errorMsg('订单状态错误');
}
$config_model = new Config();
$config = $config_model->dataInfo(['uniacid'=>$this->_uniacid]);
$update = [
'pay_type' => 3,
'send_time'=> time(),
'auto_receiving_time' => $config['auto_hx_time']*86400+time()
];
Db::startTrans();
$res = $send_order_model->dataUpdate(['id'=>$input['id']],$update);
if($res==0){
Db::rollback();
$this->errorMsg('发货失败');
}
if($send_order['type']==1){
$claim_order_model = new ClaimOrder();
$claim_order_model->dataUpdate(['id'=>$send_order['order_id']],['pay_type'=>3]);
}
Db::commit();
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2022-07-01 15:06
* @功能说明:认养拼团列表
*/
public function collageList(){
$input = $this->_param;
$collage_model = new ClaimCollage();
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.status','>',-1];
if(!empty($input['title'])){
$dis[] = ['a.title','like','%'.$input['title'].'%'];
}
if(!empty($input['goods_name'])){
$dis[] = ['b.title','like','%'.$input['goods_name'].'%'];
}
$data = $collage_model->adminDataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-01 15:11
* @功能说明:添加拼团
*/
public function collageAdd(){
$input = $this->_input;
$collage_model = new ClaimCollage();
$input['uniacid'] = $this->_uniacid;
$res = $collage_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-07-01 15:11
* @功能说明:添加拼团
*/
public function collageUpdate(){
$input = $this->_input;
$collage_model = new ClaimCollage();
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$res = $collage_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-07-01 15:11
* @功能说明:添加拼团
*/
public function collageInfo(){
$input = $this->_param;
$collage_model = new ClaimCollage();
$dis = [
'id' => $input['id']
];
$res = $collage_model->dataInfo($dis);
$claim_model = new Claim();
$res['claim_title'] = $claim_model->where(['id'=>$res['claim_id']])->value('title');
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 15:28
* @功能说明:认养管理列表
*/
public function claimList(){
$input = $this->_param;
$claim_model = new Claim();
$dis[] = ['uniacid','=',$this->_uniacid];
if(isset($input['status'])){
$dis[] = ['status','=',$input['status']];
}else{
$dis[] = ['status','>',-1];
}
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$data = $claim_model->dataList($dis,$input['limit']);
if(!empty($data['data'])){
$farmer_model = new Farmer();
$cate_model = new LandCate();
foreach ($data['data'] as &$v){
$v['farmer_name'] = $farmer_model->where(['id'=>$v['farmer_id']])->value('title');
$cate_name = $cate_model->where('id','in',$v['cate_id'])->column('title');
$v['cate_name'] = implode(',',$cate_name);
}
}
$arr = [
0 => 'off_num',
1 => 'on_num',
];
foreach ($arr as $key => $value){
$dis = [
'uniacid' => $this->_uniacid,
'status' => $key
];
$data[$value] = $claim_model->where($dis)->count();
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 16:32
* @功能说明:添加认养
*/
public function claimAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$claim_model = new Claim();
$res = $claim_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 16:32
* @功能说明:认养详情
*/
public function claimInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$claim_model = new Claim();
$res = $claim_model->dataInfo($dis);
$claim_text_model = new ClaimText();
$monitor_text_model= new MonitorText();
//流程
$res['process'] = $claim_text_model->where(['claim_id'=>$input['id']])->select()->toArray();
//监控
$res['monitor'] = $monitor_text_model->where(['obj_id'=>$input['id'],'type'=>2])->column('monitor_id');
$res['monitor'] = array_values($res['monitor']);
$freightTemplate_model = new FreightTemplate();
$res['send_template_type'] = $freightTemplate_model->where(['id'=>$res['send_tmpl_id']])->value('type');
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 16:32
* @功能说明:编辑认养
*/
public function claimUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$claim_model = new Claim();
$res = $claim_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 16:32
* @功能说明:编辑认养
*/
public function claimStatusUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$claim_model = new Claim();
$res = $claim_model->where($dis)->update($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-31 15:11
* @功能说明:认养和土地分类
*/
public function landAndClaimCate(){
$input = $this->_param;
$dis = [
'a.status' => 1,
'a.uniacid'=> $this->_uniacid,
'a.type' => $input['type']
];
$where = [];
if(!empty($input['farmer_id'])){
$where = [
'a.is_public' => 1,
'b.farmer_id' => $this->farmer['id']
];
}
$cate_model = new LandCate();
$data = $cate_model->alias('a')
->join('lbfarm_land_cate_text b','a.id = b.cate_id','left')
->where($dis)
->where(function ($query) use ($where){
$query->whereOr($where);
})
->field('a.*')
->group('a.id')
->order('a.top desc,a.id desc')
->select()
->toArray();
return $this->success($data);
}
}

View File

@@ -0,0 +1,372 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\BagAtv;
use app\farm\model\Coupon;
//use app\farm\model\CouponAtv;
//use app\farm\model\CouponAtvRecord;
use app\farm\model\CouponRecord;
use think\App;
use app\shop\model\Order as Model;
use think\facade\Db;
class AdminCoupon extends AdminRest
{
protected $model;
protected $atv_model;
protected $record_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Coupon();
$this->atv_model = new BagAtv();
$this->record_model = new CouponRecord();
}
/**
* @author chenniang
* @DataTime: 2021-07-04 19:09
* @功能说明:优惠券列表
*/
public function couponList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
if(!empty($input['status'])){
$dis[] = ['status','=',$input['status']];
}else{
$dis[] = ['status','>',-1];
}
if(isset($input['send_type'])){
$dis[] = ['send_type','=',$input['send_type']];
}
if(!empty($input['name'])){
$dis[] = ['title','like','%'.$input['name'].'%'];
}
$data = $this->model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:56
* @功能说明:添加优惠券
*/
public function couponAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$res = $this->model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:57
* @功能说明:编辑优惠券
*/
public function couponUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$res = $this->model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-02 09:51
* @功能说明:卡券上下架删除
*/
public function couponStatusUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
//删除优惠券 需要判断该优惠券是否正在参加活动
if(isset($input['status'])&&$input['status']==-1){
$atv_record_model = new CouponAtvRecord();
$have_atv = $atv_record_model->couponIsAtv($input['id']);
if($have_atv==true){
$this->errorMsg('该优惠券正在参加活动,只有等用户发起等活动结束后才能删除');
}
}
$res = $this->model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-04 18:59
* @功能说明:优惠券详情
*/
public function couponInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$res = $this->model->dataInfo($dis);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-06 19:19
* @功能说明:活动详情
*/
public function couponAtvInfo(){
$input = $this->_param;
$dis = [
'uniacid' => $this->_uniacid
];
$data = $this->atv_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-06 19:22
* @功能说明:活动编辑
*/
public function couponAtvUpdate(){
$input = $this->_input;
$dis = [
'uniacid' => $this->_uniacid
];
$input['uniacid'] = $this->_uniacid;
$data = $this->atv_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-12 16:26
* @功能说明:后台派发卡劵
*/
public function couponRecordAdd(){
$input = $this->_input;
foreach ($input['user'] as $value){
$res = $this->record_model->recordAdd($input['coupon_id'],$value['id'],$value['num']);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 14:31
* @功能说明:优惠券下拉框
*/
public function couponSelect(){
$dis = [
'uniacid' => $this->_uniacid,
'status' => 1
];
$data = $this->model->where($dis)->order('id desc')->select()->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 14:36
* @功能说明:活动列表
*/
public function bagAtvList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like',"%".$input['title'].'%'];
}
$data = $this->atv_model->dataList($dis,$input['limie']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 14:39
* @功能说明:添加活动
*/
public function bagAtvAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$input = $this->atv_model->changeData($input);
$res = $this->atv_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 14:39
* @功能说明:添加活动
*/
public function bagAtvUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$input = $this->atv_model->changeData($input);
$res = $this->atv_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 14:39
* @功能说明:添加活动
*/
public function bagAtvInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$res = $this->atv_model->dataInfo($dis);
return $this->success($res);
}
}

View File

@@ -0,0 +1,693 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\ClaimOrder;
use app\farm\model\Farmer;
use app\farm\model\FinanceWater;
use app\farm\model\LandOrder;
use app\farm\model\ShopOrder;
use app\farm\model\User;
use app\farm\model\Wallet;
use app\shop\model\DistributionCash;
use app\shop\model\DistributionList;
use longbingcore\wxcore\Excel;
use think\App;
use app\shop\model\Order as Model;
class AdminExcel extends AdminRest
{
protected $model;
protected $order_goods_model;
protected $refund_order_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new LandOrder();
}
/**
* @author chenniang
* @DataTime: 2021-03-15 14:43
* @功能说明:列表
*/
public function landOrderList(){
$input = $this->_param;
$order_model = new LandOrder();
$farmer_model = new Farmer();
$user_model = new User();
//初始化订单
$order_model->orderInit();
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}
if(!empty($input['order_code'])){
$dis[] = ['a.order_code','like','%'.$input['order_code'].'%'];
}
if(!empty($input['goods_name'])){
$dis[] = ['a.goods_name','like','%'.$input['goods_name'].'%'];
}
if(!empty($input['mobile'])){
$dis[] = ['b.mobile','like','%'.$input['mobile'].'%'];
}
if(!empty($input['farmer_id'])){
$dis[] = ['a.farmer_id','=',$input['farmer_id']];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$data = $order_model->adminDataSelect($dis);
if(!empty($data)){
foreach ($data as &$vs){
$vs['farmer_info'] = $farmer_model->dataInfo(['id'=>$vs['farmer_id']],'title');
$vs['user_info'] = $user_model->dataInfo(['id'=>$vs['user_id']]);
}
}
$name = '土地订单列表';
$header=[
'订单ID',
'商品名',
'到期时间',
'面积',
'农场名称',
'服务类型',
'租赁人',
'租赁人手机号',
'下单人',
'下单人手机号',
'实收金额',
'系统订单号',
'付款订单号',
'下单时间',
'支付方式',
'状态',
];
$new_data = [];
foreach ($data as $v){
$info = array();
$info[] = $v['id'];
$info[] = $v['goods_name'];
$info[] = date('Y-m-d H:i:s',$v['end_time']);
$info[] = $v['area'].'m²';
$info[] = !empty($v['farmer_info']['title'])?$v['farmer_info']['title']:'';
$info[] = $v['massif_title'];
$info[] = $v['rent_user_name'];
$info[] = $v['rent_mobile'];
$info[] = $v['user_name'];
$info[] = $v['mobile'];
$info[] = $v['pay_price'];
$info[] = $v['order_code'];
$info[] = $v['transaction_id'];
$info[] = $v['create_time']?date('Y-m-d H:i:s',$v['create_time']):'暂无信息';
$info[] = !empty($v['balance'])&&$v['balance']>0?'余额支付':'微信支付';
$info[] = $this->orderStatusText($v['pay_type']);
$new_data[] = $info;
}
$excel = new Excel();
$excel->excelExport($name,$header,$new_data);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-28 11:26
* @功能说明:用户下单列表
*/
public function claimOrderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}
if(!empty($input['order_code'])){
$dis[] = ['a.order_code','like','%'.$input['order_code'].'%'];
}
if(!empty($input['goods_name'])){
$dis[] = ['a.goods_name','like','%'.$input['goods_name'].'%'];
}
if(!empty($input['mobile'])){
$dis[] = ['b.mobile','like','%'.$input['mobile'].'%'];
}
if(!empty($input['farmer_id'])){
$dis[] = ['a.farmer_id','=',$input['farmer_id']];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$order_model = new ClaimOrder();
$farmer_model = new Farmer();
$user_model = new User();
$data = $order_model->adminDataSelect($dis);
if(!empty($data)){
foreach ($data as &$vs){
$vs['farmer_info'] = $farmer_model->dataInfo(['id'=>$vs['farmer_id']],'title');
$vs['user_info'] = $user_model->dataInfo(['id'=>$vs['user_id']]);
}
}
$name = '认养订单列表';
$header=[
'订单ID',
'商品名',
'数量',
'配送周期',
'农场名称',
'认养编号',
'下单人',
'下单人手机号',
'实收金额',
'系统订单号',
'付款订单号',
'下单时间',
'支付方式',
'配送方式',
'状态',
];
$new_data = [];
foreach ($data as $v){
$info = array();
$info[] = $v['id'];
$info[] = $v['goods_name'];
$info[] = $v['num'];
$info[] = $v['send_cycle'].'共'.$v['send_times'].'次';
$info[] = $v['farmer_info']['title'];
$info[] = $v['claim_code'];
$info[] = $v['user_name'];
$info[] = $v['mobile'];
$info[] = $v['pay_price'];
$info[] = $v['order_code'];
$info[] = $v['transaction_id'];
$info[] = $v['create_time']?date('Y-m-d H:i:s',$v['create_time']):'暂无信息';
$info[] = !empty($v['balance'])&&$v['balance']>0?'余额支付':'微信支付';
$info[] = $v['send_type']==1?'自提':'快递';
$info[] = $this->orderStatusText($v['pay_type'],2);
$new_data[] = $info;
}
$excel = new Excel();
$excel->excelExport($name,$header,$new_data);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-08 14:55
* @功能说明:商城订单导出
*/
public function shopOrderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$where = [];
if(!empty($input['name'])){
$where[] = ['b.goods_name','like','%'.$input['name'].'%'];
$where[] = ['a.order_code','like','%'.$input['name'].'%'];
}
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}
if(!empty($input['store_id'])){
$dis[] = ['a.store_id','=',$input['store_id']];
}
$order_model = new ShopOrder();
$data = $order_model->adminDataSelect($dis,$where);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-30 16:32
* @功能说明:
*/
public function orderStatusText($status,$type=1){
switch ($status){
case 1:
return '待支付';
break;
case 2:
return $type==1?'租赁中':'认养中';
break;
case 3:
return '配送中';
break;
case 7:
return '已完成';
break;
case -1:
return '已取消';
break;
}
}
/**
* @author chenniang
* @DataTime: 2021-03-18 13:37
* @功能说明:财务数据统计导出
*/
public function dateCount(){
$input = $this->_param;
$water_model = new FinanceWater();
if($input['type']==1){
$where[] = ['farmer_id','=',$input['farmer_id']];
}else{
$where[] = ['store_id','=',$input['farmer_id']];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$where[] = ['create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
// dump($where);exit;
$data = $water_model->where($where)->field('create_date')->group('create_date')->select()->toArray();
if(!empty($data)){
foreach ($data as &$vs){
//查询各个类型的单日的流水除去余额
$date_water = $water_model->getDateList($input['farmer_id'],$vs['create_date'],$input['type']);
$vs = array_merge($vs,$date_water);
//查询当前余额
$day_water = $water_model->getDayCash($input['farmer_id'],$input['type'],$vs['create_date']);
$vs['cash'] = $day_water['cash'];
}
}
$farmer_model = new Farmer();
$farmer_name = $farmer_model->where(['id'=>$input['farmer_id']])->value('title');
$name = $farmer_name.'账务列表';
$header=[
'收支时间',
'土地订单收入(元)',
'土地配送收入(元)',
'认养订单收入(元)',
'认养配送收入(元)',
'养殖订单收入(元)',
'提现(元)',
'余额(元)',
];
$new_data = [];
foreach ($data as $v){
$info = array();
$info[] = $v['create_date'];
$info[] = $v['land_cash'];
$info[] = $v['land_send_cash'];
$info[] = $v['claim_cash'];
$info[] = $v['claim_send_cash'];
$info[] = $v['breed_cash'];
$info[] = $v['wallet_cash'];
$info[] = $v['cash'];
$new_data[] = $info;
}
$excel = new Excel();
$excel->excelExport($name,$header,$new_data);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 14:48
* @功能说明:用户收益列表
*/
public function userProfitListExcel(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$where = [];
if(!empty($input['name'])){
$where[] = ['a.nickName','like','%'.$input['name'].'%'];
$where[] = ['b.user_name','like','%'.$input['name'].'%'];
}
$fx_model = new DistributionList();
$cash_model = new DistributionCash();
$wallet_model = new Wallet();
$data = $fx_model->userProfitSelect($dis,$where);
if(!empty($data)){
foreach ($data as &$v){
//产生收益
$v['total_fx_cash'] = $cash_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('cash');
//未入账
$v['unrecorded_fx_cash'] = $cash_model->where(['user_id'=>$v['id']])->where('status','in',[1])->sum('cash');
//累计提现
$v['total_wallte_cash'] = $wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('pay_price');
//提现中
$v['wallte_ing_cash'] = $wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1])->sum('pay_price');
}
}
$name = '收益信息列表';
$header=[
'ID',
'姓名',
'微信昵称',
'总收益',
'总提现',
'提现中',
'未入账',
'当前余额',
];
$new_data = [];
if(!empty($data)){
foreach ($data as $v){
$info = array();
$info[] = $v['id'];
$info[] = !empty($v['user_name'])?$v['user_name']:'';
$info[] = $v['nickName'];
$info[] = $v['total_fx_cash'];
$info[] = $v['total_wallte_cash'];
$info[] = $v['wallte_ing_cash'];
$info[] = $v['unrecorded_fx_cash'];
$info[] = $v['fx_cash'];
$new_data[] = $info;
}
}
$excel = new Excel();
$excel->excelExport($name,$header,$new_data);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 10:17
* @功能说明:分销商列表导出
*/
public function userRelationshipListExcel(){
$input = $this->_param;
$dis = [
'uniacid' => $this->_uniacid,
'is_fx' => 1
];
$user_model = new User();
$cash_model = new DistributionCash();
$wallet_model = new Wallet();
$data = $user_model->where($dis)->field('id,avatarUrl,nickName,pid,fx_bind_time,fx_cash')->order('fx_bind_time')->select()->toArray();
if(!empty($data)){
foreach ($data as &$v){
$v['top_name'] = $user_model->where(['id'=>$v['pid'],'is_fx'=>1])->value('nickName');
//产生收益
$v['total_fx_cash'] = $cash_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('cash');
//累计提现
$v['wallte_cash'] = $wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('pay_price');
}
}
$name = '分销商列表';
$header=[
'ID',
'微信昵称',
'产生收益(元)',
'总收益(元)',
'已提现(元)',
'上线id',
'上线昵称',
'创建时间',
];
$new_data = [];
if(!empty($data)){
foreach ($data as $v){
$info = array();
$info[] = $v['id'];
$info[] = $v['nickName'];
$info[] = $v['total_fx_cash'];
$info[] = $v['fx_cash'];
$info[] = $v['wallte_cash'];
$info[] = $v['pid'];
$info[] = !empty($v['top_name']);
$info[] = date('Y-m-d H:i:s',$v['fx_bind_time']);
$new_data[] = $info;
}
}
$excel = new Excel();
$excel->excelExport($name,$header,$new_data);
return $this->success($data);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,582 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\ShopGoods;
use app\farm\model\ShopGoodsCate;
use app\member\model\DiscountGoods;
use think\App;
use app\shop\model\Goods as Model;
use think\facade\Db;
class AdminGoods extends AdminRest
{
protected $model;
protected $cate_model;
protected $spe_model;
protected $spe_price_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new ShopGoods();
$this->cate_model = new ShopGoodsCate();
$this->spe_model = new Shop;
$this->spe_price_model = new GoodsSpePrice();
}
/**
* @author chenniang
* @DataTime: 2021-10-21 11:01
* @功能说明:商品分类列表
*/
public function goodsCateList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$data = $this->cate_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-10-21 11:17
* @功能说明:添加分类
*/
public function goodsCateAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$data = $this->cate_model->dataAdd($input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-10-21 11:18
* @功能说明:编辑分类
*/
public function goodsCateUpdate(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$dis = [
'id' => $input['id']
];
$data = $this->cate_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-10-21 11:18
* @功能说明:编辑分类
*/
public function goodsCateInfo(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$dis = [
'id' => $input['id']
];
$data = $this->cate_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-10-21 17:58
* @功能说明:分类下拉框
*/
public function goodsCateSelect(){
$input['uniacid'] = $this->_uniacid;
$dis = [
'uniacid' => $this->_uniacid,
'status' => 1
];
$data = $this->cate_model->where($dis)->select()->toArray();
return $this->success($data);
}
/**
* 获取商品列表
*/
public function goodsList(){
$input= $this->_param;
$dis[]= ['uniacid','=',$this->_uniacid];
if(!empty($input['name'])){
$dis[] = ['name','like',"%".$input['name']."%"];
}
if(!empty($input['cate'])){
$dis[] = ['type','=',$input['cate']];
}
//自提
if(!empty($input['is_self'])){
$dis[] = ['is_self','=',$input['is_self']];
}
//快递
if(!empty($input['is_send'])){
$dis[] = ['is_send','=',$input['is_send']];
}
$sale_type = $input['type']==2?0:1;
$sale_out_goods = $this->spe_price_model->getSellOut($this->_uniacid,$sale_type);
switch ($input['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->model->dataList($dis,$this->_input['limit']);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
//总库存
$v['all_stock'] = $this->spe_price_model->getGoodsStock($v['id']);
//规格
$v['spe_info'] = $this->goodsSpeList($v['id']);
$v['cate_text'] = $this->cate_model->where(['id'=>$v['type']])->value('title');
}
}
//销售中
$data['sale_ing'] = $this->model->saleIngCount($this->_uniacid);
//售罄
$data['sale_out'] = $this->model->saleIngCount($this->_uniacid,2);
//下架
$data['sale_end'] = $this->model->saleIngCount($this->_uniacid,3);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-10-21 11:33
* @功能说明:添加商品
*/
public function goodsAdd(){
$input = $this->_input;
$data = $this->model->returnData($input);
$discount_data = $input['memberForm']['discount_data'];
$data['uniacid'] = $this->_uniacid;
Db::startTrans();
$goods_id = $this->model->dataAdd($data);
$spe_arr = $this->goodsSpeAdd($input['specsForm']['specsItem'],$goods_id);
$spe_res = $this->goodsSpePriceAdd($input['specsForm']['specsTable'],$goods_id,$spe_arr);
//会员折扣模型
$discount_model = new DiscountGoods();
//会员折扣
$res = $discount_model->goodsAdd($discount_data,$this->_uniacid,$goods_id);
Db::commit();
return $this->success($res);
}
/**
* 修改商品
*/
public function goodsUpdate(){
$input= $this->_input;
//会员折扣模型
$discount_model = new DiscountGoods();
$dis = is_array($input['id'])? ['id','in',$input['id']]:['id' =>$input['id']];
$discount_data = $input['memberForm']['discount_data'];
Db::startTrans();
$data = $this->model->returnData($input);
//判断商品名字长度
if(strlen($data['name'])>110){
$this->errorMsg('商品名字不得超过110字符当前字符'.strlen($data['name']));
}
if(isset($data['is_limit'])&&$data['is_limit']==2&&$data['start_min']>$data['limit']){
$this->errorMsg('起购数不能大于限购');
}
$this->model->goodsUpdate($dis,$data);
$this->spe_model->goodsSpeUpdate(['uniacid'=>$this->_uniacid,'goods_id'=>$input['id']],['status'=>-1]);
$this->spe_price_model->goodsSpePriceUpdate(['uniacid'=>$this->_uniacid,'goods_id'=>$input['id']],['status'=>-1]);
$spe_arr = $this->goodsSpeAdd($input['specsForm']['specsItem'],$input['id']);
$res = $this->goodsSpePriceAdd($input['specsForm']['specsTable'],$input['id'],$spe_arr);
if($data['is_parameter']==1 && empty($input['parameter'])){
return $this->error('请添加商品参数');
}
//会员折扣
$discount_model->goodsAdd($discount_data,$this->_uniacid,$input['id']);
Db::commit();
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-10-21 11:21
* @功能说明:分类详情
*/
public function goodsInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
//会员折扣模型
$discount_model = new DiscountGoods();
$res['goods_info'] = $this->model->dataInfo($dis);
$res['spe_info'] = $this->goodsSpeList($input['id']);
//会员商品信息
$res['memberForm']['is_discount'] = $res['goods_info']['is_discount'];
//商品折扣信息
$res['memberForm']['discount_data'] = $discount_model->goodsDiscount($input['id']);
return $this->success($res);
}
/**
* 获取商品规格
*/
public function goodsSpeList($goods_id){
$dis['goods_id'] = $goods_id;
$dis['status'] = 1;
$data['text'] = $this->spe_model->goodsSpe($dis);
$data['price'] = $this->spe_price_model->goodsSpePrice($dis);
if(!empty($data['price'])){
foreach ($data['price'] as &$v){
$v['title'] = $v['spe_name_text'];
$v['true_id'] = $v['id'];
$v['id'] = implode(',',$v['spe_array_text']);
}
}
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-08-26 10:09
* @功能说明:列表页修改商品库存
*/
public function updateSpe(){
$input= $this->_input;
$input= $input['stock'];
if(!empty($input)&&!is_array($input)){
$this->errorMsg('数据错误');
}
foreach ($input as $value){
$this->spe_price_model->goodsSpePriceUpdate(['id'=>$value['id']],['stock'=>$value['stock']]);
}
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2021-10-28 10:33
* @功能说明:修改商品基本的参数
*/
public function goodsBasicUpdate(){
$input= $this->_input;
$dis = [
'id' => $input['id']
];
$res = $this->model->goodsUpdate($dis,$input);
return $this->success($res);
}
/**
* 上下架删除商品
*/
public function goodsStatusUpdate(){
$input= $this->_input;
if(isset($input['status'])){
$data = ['status'=>$input['status']];
}else{
$data = ['index_show'=>$input['index_show']];
}
$res = $this->model->goodsUpdateStatus($data,$input['id']);
return $this->success($res);
}
/**
* @param $data
* @param $goods_id
* @return array
* 添加多规格
*/
public function goodsSpeAdd($data,$goods_id){
/**
* 循环判断是否存在多个规格名添加图片的问题
* @date 2020/5/14 10:42 --lichuanming
*/
$isimg_count = 0;
foreach ($data as $item ){
if($item['is_img'] == 1){
$isimg_count++;
}
}
if($isimg_count > 1){
return $this->error('当前已有规格名添加了图片,继续添加则需取消上一个规格名的图片勾选');
}
$arr = array();
if(!empty($data)){
foreach ($data as $v){
$is_img = $v['is_img']?$v['is_img']:0; #@date 2020/5/14 10:42 --lichuanming
if(strlen($v['pid'])>10){
$pid = $this->spe_model->goodsSpeAdd(['uniacid'=>$this->_uniacid,'goods_id'=>$goods_id,'title'=>$v['title'],'is_img'=>$is_img]);
}else{
$this->spe_model->goodsSpeUpdate(['id'=>$v['id']],['status'=>1,'title'=>$v['title'],'is_img'=>$is_img]);
$pid = $v['id'];
}
if(!empty($v['cate'])){
foreach ($v['cate'] as $value){
$image = $is_img?$value['image']:''; #@date 2020/5/14 10:42 --lichuanming
if(strlen($value['id'])>10) {
$id = $this->spe_model->goodsSpeAdd(['uniacid' => $this->_uniacid, 'goods_id' => $goods_id, 'title' => $value['title'], 'pid' => $pid,'is_img'=>$is_img,'image'=>$image]);
}else{
$this->spe_model->goodsSpeUpdate(['id'=>$value['id']],['status'=>1,'title'=>$value['title'],'is_img'=>$is_img,'image'=>$image]);
$id = $value['id'];
}
$arr[$value['id']] = $id;
}
}
}
}
return $arr;
}
/**
* @param $data
* @param $good_id
* @param $arr
* @return int|string
* 添加多规格价格
*/
public function goodsSpePriceAdd($data,$good_id,$arr){
if(!empty($data)){
foreach ($data as $v){
if (strlen($v['price'])>8||strlen($v['original_price'])>8){
$this->errorMsg('价格最多8位');
}
$pid = explode(',',$v['id']);
$spe_id = [];
if(empty($arr)){
$this->errorMsg('规格不正确,请删除错误规格,重新编辑');
}
foreach ($pid as $value){
if(!key_exists($value,$arr)){
$this->errorMsg('规格不正确,请删除错误规格,重新编辑');
}
$spe_id[] = $arr[$value];
}
$spe_price_id = implode('-',$spe_id);
$ins['uniacid'] = $this->_uniacid;
$ins['goods_id']= $good_id;
$ins['spe_id_1']= $spe_price_id;
$ins['price'] = $v['price'];
$ins['stock'] = $v['stock'];
// $ins['alert_stock'] = $v['alert_stock'];
$ins['status'] = 1;
//原价
$ins['original_price'] = !empty($v['original_price'])?$v['original_price']:0;
//成本价
$ins['cost_price'] = !empty($v['cost_price'])?$v['cost_price']:0;
$spe_price = $this->spe_price_model->singeSpePrice(['goods_id'=>$good_id,'spe_id_1'=>$spe_price_id,'uniacid'=>$this->_uniacid]);
if(empty($spe_price)) {
$res = $this->spe_price_model->goodsSpePriceAdd($ins);
}else{
$res = $this->spe_price_model->goodsSpePriceUpdate(['id'=>$spe_price['id']],$ins);
}
}
}
return !empty($res)?$res:1;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,175 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\BalanceCard;
use app\farm\model\BalanceOrder;
use app\farm\model\LandList;
use app\farm\model\Massif;
use app\farm\server\Land;
use think\App;
use think\facade\Db;
class AdminMassif extends AdminRest
{
protected $model;
protected $massif_model;
protected $land_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new BalanceCard();
$this->massif_model = new Massif();
$this->land_model = new LandList();
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:43
* @功能说明:地块列表
*/
public function massifList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$data = $this->massif_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:43
* @功能说明:地块列表下拉框
*/
public function massifSelect(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$data = $this->massif_model->where($dis)->select()->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:49
* @功能说明:添加地块
*/
public function massifAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$data = $this->massif_model->dataAdd($input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:50
* @功能说明:编辑地块
*/
public function massifUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
//删除
if(isset($input['status'])&&$input['status']==-1){
$find = $this->land_model->landSomeFind($input['id'],1);
if($find==1){
$this->errorMsg('该地块服务正在被使用');
}
}
$data = $this->massif_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:50
* @功能说明:地块详情
*/
public function massifInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->massif_model->dataInfo($dis);
return $this->success($data);
}
}

View File

@@ -0,0 +1,451 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\ApiRest;
use app\farm\model\Config;
use app\farm\model\Coupon;
use app\farm\model\CouponRecord;
use app\farm\model\ShopOrder;
use app\farm\model\ShopOrderGoods;
use app\farm\model\ShopRefund;
use app\farm\model\Goods;
use app\farm\model\MsgConfig;
use app\farm\model\Order;
use app\farm\model\OrderAddress;
use app\farm\model\OrderGoods;
use app\farm\model\RefundOrder;
use app\farm\model\SystemInfo;
use app\shfarmop\model\User;
use longbingcore\wxcore\PushMsgModel;
use think\App;
use think\facade\Db;
use think\Request;
class AdminOrder extends AdminRest
{
protected $model;
protected $refund_model;
protected $order_goods_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new ShopOrder();
$this->refund_model = new ShopRefund();
$this->order_goods_model = new ShopOrderGoods();
autoCancelOrder($this->_uniacid);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:48
* @功能说明:个人中心
*/
public function orderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['goods_name'])){
$dis[] = ['c.goods_name','like','%'.$input['goods_name'].'%'];
}
if(!empty($input['order_code'])){
$dis[] = ['a.order_code','like','%'.$input['order_code'].'%'];
}
if(!empty($input['mobile'])){
$dis[] = ['d.mobile','like','%'.$input['mobile'].'%'];
}
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}
if(!empty($input['store_id'])){
$dis[] = ['a.store_id','=',$input['store_id']];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$data = $this->model->adminDataList($dis,$input['limit']);
$arr = [
//未支付
'no_pay_count' => 1,
//未发货
'no_send_count' => 2,
//已经发货
'have_send_count'=> 3
];
foreach ($arr as $ks=>$vs){
$map = [
'pay_type'=> $vs
];
$data[$ks] = $this->model->where($map)->count();
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-15 14:58
* @功能说明:订单详情
*/
public function orderInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->model->dataInfo($dis);
$data['over_time'] -= time();
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
$data['hx_time'] = date('Y-m-d H:i:s',$data['hx_time']);
//剩余可申请退款数量
$can_refund_num = array_sum(array_column($data['order_goods'],'can_refund_num'));
//是否可以申请退款
if(($data['pay_type']==7&&$data['can_refund_time']>time()&&$can_refund_num>0)||($data['pay_type']==2&&$can_refund_num>0)){
$data['can_refund'] = 1;
}else{
$data['can_refund'] = 0;
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 17:29
* @功能说明:退款订单详情
*
*/
public function refundOrderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$where = [];
if(!empty($input['order_code'])){
$where[] = ['a.order_code','like','%'.$input['order_code'].'%'];
$where[] = ['d.order_code','like','%'.$input['order_code'].'%'];
}
if(!empty($input['goods_name'])){
$dis[] = ['c.goods_name','like','%'.$input['goods_name'].'%'];
}
// if(!empty($input['order_code'])){
//
// $dis[] = ['d.order_code','like','%'.$input['order_code'].'%'];
//
// }
if(!empty($input['status'])){
$dis[] = ['a.status','=',$input['status']];
}else{
$dis[] = ['a.status','>',-1];
}
$data = $this->refund_model->indexDataList($dis,$where,$input['limit']);
$map = [
'status' => 1,
// 'user_id'=> $this->getUserId()
];
//退款中数量
$data['ing_count'] = $this->refund_model->where($map)->count();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 17:50
* @功能说明:退款订单详情
*/
public function refundOrderInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->refund_model->dataInfo($dis);
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
$data['refund_time'] = date('Y-m-d H:i:s',$data['refund_time']);
$order_model = new ShopOrder();
$data['pay_order_code'] = $order_model->where(['id'=>$data['order_id']])->value('order_code');
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 17:14
* @功能说明:楼长核销订单
*/
public function endOrder(){
$input = $this->_input;
$order_model= new ShopOrder();
$order = $order_model->dataInfo(['id'=>$input['id']]);
if(empty($order)){
$this->errorMsg('订单未找到');
}
if(empty($order)){
$this->errorMsg('订单未找到');
}
//自提
if($order['send_type']==1&&$order['pay_type']!=2){
$this->errorMsg('订单状态错误');
}
//快递
if($order['send_type']==2&&$order['pay_type']!=3){
$this->errorMsg('订单状态错误');
}
if($order['send_type']==1){
$user_model = new \app\massage\model\User();
$role = $user_model->where(['id'=>$this->getUserId()])->value('role');
if($role!=1){
$this->errorMsg('只有管理员才能核销');
}
}
$refund_model = new ShopRefund();
//判断有无申请中的退款订单
$refund_order = $refund_model->dataInfo(['order_id'=>$order['id'],'status'=>1]);
if(!empty($refund_order)){
$this->errorMsg('该订单正在申请退款,请先处理再核销');
}
$res = $order_model->hxOrder($input['id'],$this->getUserId());
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-18 09:21
* @功能说明:拒绝退款
*/
public function noPassRefund(){
$input = $this->_input;
$refund_order_model = new ShopRefund();
$res = $refund_order_model->noPassRefund($input['id'],$this->_user['id'],1);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success($res);
}
/**\
* @author chenniang
* @DataTime: 2021-03-18 09:28
* @功能说明:同意退款
*/
public function passRefund(){
$input = $this->_input;
$refund_order_model = new ShopRefund();
$res = $refund_order_model->passOrder($input['id'],$input['price'],$this->payConfig(),$this->_user['id'],$input['text'],1);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-03-07 11:08
* @功能说明:地主商城订单发货
*/
public function shopOrderSend(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$order_model = new ShopOrder();
$order = $order_model->dataInfo($dis);
if(empty($order)||$order['pay_type']!=2){
$this->errorMsg('订单状态错误');
}
$refund_model = new ShopRefund();
//判断有无申请中的退款订单
$refund_order = $refund_model->dataInfo(['order_id'=>$input['id'],'status'=>1]);
if(!empty($refund_order)){
$this->errorMsg('该订单正在申请退款,请先处理再核销');
}
$config_model = new Config();
$config = $config_model->dataInfo(['uniacid'=>$this->_uniacid]);
$update = [
'pay_type' => 3,
// 'express_company' => $input['express_company'],
//
// 'express_code' => $input['express_code'],
//
// 'express_mobile' => $input['express_mobile'],
//
// 'express_user' => $input['express_user'],
'send_time' => time(),
'hx_over_time' => time()+$config['auto_hx_time']*86400,
];
$data = $order_model->dataUpdate($dis,$update);
// $water_model = new FinanceWater();
// //商城订单农场主获得运费
// $water_model->addWater($order['id'],16,1,0);
$order = $order_model->dataInfo($dis);
$order_model->sendOrderService($order);
$sys_model = new PushMsgModel($order['uniacid']);
$sys_model->sendMsg($order,4);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 15:27
* @功能说明:上传视频
*/
public function uploadVideo(){
$input = $this->_input;
$res = $this->model->dataUpdate(['id'=>$input['id']],['video'=>$input['video']]);
return $this->success($res);
}
}

View File

@@ -0,0 +1,436 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\ClaimOrder;
use app\farm\model\Farmer;
use app\farm\model\FinanceWater;
use app\farm\model\LandCateText;
use app\farm\model\LandOrder;
use app\farm\model\Machine;
use app\farm\model\Monitor;
use app\farm\model\SendOrder;
use app\farm\model\User;
use app\farm\model\LandCate;
use app\farm\model\Wallet;
use app\shop\model\DistributionCash;
use app\shop\model\DistributionList;
use app\shop\model\StoreGoods;
use longbingcore\wxcore\PospalApi;
use longbingcore\wxcore\WxPay;
use longbingcore\wxcore\YsCloudApi;
use think\App;
use app\farm\model\Farmer as Model;
use think\facade\Db;
class AdminReseller extends AdminRest
{
protected $model;
protected $user_model;
protected $cash_model;
protected $wallet_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new DistributionList();
$this->cash_model = new DistributionCash();
$this->user_model = new User();
$this->wallet_model = new Wallet();
}
/**
* @author chenniang
* @DataTime: 2021-03-15 14:43
* @功能说明:列表
*/
public function resellerList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['status'])){
$dis[] = ['a.status','=',$input['status']];
}else{
$dis[] = ['a.status','>',-1];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$start_time = $input['start_time'];
$end_time = $input['end_time'];
$dis[] = ['a.create_time','between',"$start_time,$end_time"];
}
$where = [];
if(!empty($input['name'])){
$where[] = ['a.user_name','like','%'.$input['name'].'%'];
$where[] = ['a.mobile','like','%'.$input['name'].'%'];
}
$data = $this->model->adminDataList($dis,$input['limit'],$where);
$list = [
0=>'all',
1=>'ing',
2=>'pass',
4=>'nopass'
];
foreach ($list as $k=> $value){
$dis_s = [];
$dis_s[] =['uniacid','=',$this->_uniacid];
if(!empty($k)){
$dis_s[] = ['status','=',$k];
}else{
$dis_s[] = ['status','>',-1];
}
$data[$value] = $this->model->where($dis_s)->count();
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 10:17
* @功能说明:用户管理列表
*/
public function userRelationshipList(){
$input = $this->_param;
$dis = [
'uniacid' => $this->_uniacid,
'is_fx' => 1
];
$data = $this->user_model->where($dis)->field('id,avatarUrl,nickName,pid,fx_bind_time,fx_cash')->order('fx_bind_time')->paginate($input['limit'])->toArray();
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['top_info'] = $this->user_model->where(['id'=>$v['pid'],'is_fx'=>1])->field('nickName,avatarUrl')->find();
//产生收益
$v['total_fx_cash'] = $this->cash_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('cash');
//累计提现
$v['wallte_cash'] = $this->wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('pay_price');
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 10:49
* @功能说明:分销关系查找
*/
public function userRelationshipListFind(){
$input = $this->_param;
$dis = [
'is_fx' => 1
];
if($input['type']==1){
//自己
$dis['id'] = $input['user_id'];
}elseif ($input['type']==2){
//下级
$dis['pid'] = $input['user_id'];
}else{
//上级
$top_id = $this->user_model->where(['id'=>$input['user_id'],'is_fx'=>1])->value('pid');
$dis['id'] = $top_id;
}
$data = $this->user_model->where($dis)->field('id,avatarUrl,nickName,pid,fx_bind_time,fx_cash')->order('fx_bind_time')->paginate($input['limit'])->toArray();
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
//产生收益
$v['total_fx_cash'] = $this->cash_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('cash');
//累计提现
$v['wallte_cash'] = $this->wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('pay_price');
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-15 14:58
* @功能说明:分销商详情
*/
public function resellerInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->model->dataInfo($dis);
$user_model = new User();
$data['nickName'] = $user_model->where(['id'=>$data['user_id']])->value('nickName');
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-03 00:15
* @功能说明:审核(2通过,3取消,4拒绝)
*/
public function resellerUpdate(){
$input = $this->_input;
$diss = [
'id' => $input['id']
];
$info = $this->model->dataInfo($diss);
if(!empty($input['status'])&&in_array($input['status'],[2,4,-1])){
$input['sh_time'] = time();
if($input['status']==-1){
$fx_cash = $this->user_model->where(['id'=>$info['user_id']])->sum('fx_cash');
if($fx_cash>0){
$this->errorMsg('分销商还有佣金未提现');
}
$dis = [
'user_id' => $info['user_id'],
'status' => 1
];
$cash = $this->cash_model->dataInfo($dis);
if(!empty($cash)){
$this->errorMsg('分销商还有佣金未到账');
}
$dis['type'] = 5;
$wallet = $this->wallet_model->dataInfo($dis);
if(!empty($wallet)){
$this->errorMsg('分销商还有提现未处理');
}
}
}
$data = $this->model->dataUpdate($diss,$input);
if(isset($input['status'])){
$update = [
'is_fx' => 0
];
if($input['status']==2){
$update['fx_bind_time'] = time();
// $update['pid'] = $info['pid'];
$update['is_fx'] = 1;
}
$this->user_model->dataUpdate(['id'=>$info['user_id']],$update);
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 11:30
* @功能说明:分销佣金详情
*/
public function cashList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['status'])){
$dis[] = ['a.status','=',$input['status']];
}else{
$dis[] = ['a.status','>',-1];
}
$where = [];
if(!empty($input['name'])){
$where[] = ['b.user_name','like','%'.$input['name'].'%'];
$where[] = ['c.nickName','like','%'.$input['name'].'%'];
}
$data = $this->cash_model->adminCashList($dis,$where,$input['limit']);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['source_info'] = $this->user_model->where(['id'=>$v['source_id']])->field('nickName,avatarUrl')->find();
$v['order_price'] = array_sum(array_column($v['order_goods'],'pay_price'));
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-29 14:48
* @功能说明:用户收益列表
*/
public function userProfitList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$where = [];
if(!empty($input['name'])){
$where[] = ['a.nickName','like','%'.$input['name'].'%'];
$where[] = ['b.user_name','like','%'.$input['name'].'%'];
}
$data = $this->model->userProfitList($dis,$input['limit'],$where);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
//产生收益
$v['total_fx_cash'] = $this->cash_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('cash');
//未入账
$v['unrecorded_fx_cash'] = $this->cash_model->where(['user_id'=>$v['id']])->where('status','in',[1])->sum('cash');
//累计提现
$v['total_wallte_cash'] = $this->wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1,2])->sum('pay_price');
//提现中
$v['wallte_ing_cash'] = $this->wallet_model->where(['user_id'=>$v['id']])->where('status','in',[1])->sum('pay_price');
}
}
return $this->success($data);
}
}

View File

@@ -0,0 +1,218 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\BalanceCard;
use app\farm\model\BalanceOrder;
use app\farm\model\LandList;
use app\farm\model\Massif;
use app\farm\model\Seed;
use app\farm\server\Land;
use think\App;
use think\facade\Db;
class AdminSeed extends AdminRest
{
protected $model;
protected $massif_model;
protected $land_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new BalanceCard();
$this->massif_model = new Massif();
$this->land_model = new LandList();
}
/**
* @author chenniang
* @DataTime: 2021-12-20 16:54
* @功能说明:种子列表
*/
public function seedList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$seed_model = new Seed();
$data = $seed_model->dataList($dis,$input['limit']);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
// $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-20 16:54
* @功能说明:种子列表
*/
public function seedSelect(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$seed_model = new Seed();
$data = $seed_model->where($dis)->select()->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-20 16:57
* @功能说明:添加种子
*/
public function seedAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$seed_model = new Seed();
$data = $seed_model->dataAdd($input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:50
* @功能说明:编辑种子
*/
public function seedUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$seed_model = new Seed();
//删除
if(isset($input['status'])&&in_array($input['status'],[-1,0])){
$find = $this->land_model->landSomeFind($input['id'],2);
if($find==1){
$this->errorMsg('该种子正在被使用');
}
}
$data = $seed_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:50
* @功能说明:编辑种子
*/
public function seedInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$seed_model = new Seed();
$data = $seed_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 14:50
* @功能说明:编辑种子
*/
public function seedStatusUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$seed_model = new Seed();
$data = $seed_model->where($dis)->update($input);
return $this->success($data);
}
}

View File

@@ -0,0 +1,861 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\AboutUs;
use app\farm\model\SendConfig;
use app\farm\model\WelfareColumn;
use app\restaurant\model\Table;
use app\farm\model\Article;
use app\farm\model\Banner;
use app\shop\model\MsgConfig;
use app\farm\model\PayConfig;
use think\App;
use app\farm\model\Config as Model;
class AdminSetting extends AdminRest
{
protected $model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Model();
}
/**
* @author chenniang
* @DataTime: 2021-03-12 15:04
* @功能说明:配置详情
*/
public function configInfo(){
$dis = [
'uniacid' => $this->_uniacid
];
$data = $this->model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:14
* @功能说明:编辑配置
*/
public function configUpdate(){
$input = $this->_input;
$dis = [
'uniacid' => $this->_uniacid
];
if(!empty($input['app_banner'])){
$input['app_banner'] = implode(',',$input['app_banner']);
}
$data = $this->model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:15
* @功能说明:banner列表
*/
public function bannerList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['type'])){
$dis[] = ['type','=',$input['type']];
}
$banner_model = new Banner();
$data = $banner_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:18
* @功能说明:添加banner
*/
public function bannerAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$banner_model = new Banner();
$res = $banner_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:20
* @功能说明:编辑banner
*/
public function bannerUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$banner_model = new Banner();
$input['uniacid'] = $this->_uniacid;
$res = $banner_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:27
* @功能说明:banner详情
*/
public function bannerInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$banner_model = new Banner();
$res = $banner_model->dataInfo($dis);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:27
* @功能说明:新闻列表
*/
public function articleList(){
$input = $this->_param;
$article_model = new Article();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$data = $article_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:37
* @功能说明:添加文章
*
*/
public function articleAdd(){
$input = $this->_input;
$article_model = new Article();
$input['uniacid'] = $this->_uniacid;
$res = $article_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:35
* @功能说明:编辑文章
*/
public function articleUpdate(){
$input = $this->_input;
$article_model = new Article();
$dis = [
'id' => $input['id']
];
$res = $article_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:35
* @功能说明:文章详情
*/
public function articleInfo(){
$input = $this->_param;
$article_model = new Article();
$dis = [
'id' => $input['id']
];
$res = $article_model->dataInfo($dis);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:50
* @功能说明:文章下拉框
*/
public function articleSelect(){
$input = $this->_param;
$article_model = new Article();
$dis = [
'uniacid' => $this->_uniacid,
'status' => 1
];
$res = $article_model->where($dis)->field('id,title')->order('top desc,id desc')->select()->toArray();
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-18 10:53
* @功能说明:支付配置详情
*/
public function payConfigInfo(){
$dis = [
'uniacid' => $this->_uniacid
];
$pay_model = new PayConfig();
$data = $pay_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-18 10:55
* @功能说明:编辑支付配置
*/
public function payConfigUpdate(){
$input = $this->_input;
$dis = [
'uniacid' => $this->_uniacid
];
if(isset($input['cert_path'])&&isset($input['key_path'])){
if(!strstr($input['cert_path'],FILE_UPLOAD_PATH)){
$input['cert_path'] = FILE_UPLOAD_PATH.$input['cert_path'];
}
if(!strstr($input['key_path'],FILE_UPLOAD_PATH)){
$input['key_path'] = FILE_UPLOAD_PATH.$input['key_path'];
}
}
$pay_model = new PayConfig();
$data = $pay_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-31 15:16
* @功能说明:修改密码
*/
public function updatePass(){
$input = $this->_input;
$admin = new \app\farm\model\Admin();
$update = [
'passwd' => checkPass($input['pass']),
];
$res = $admin->dataUpdate(['uniacid'=>$this->_uniacid],$update);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 15:04
* @功能说明:配置详情
*/
public function msgConfigInfo(){
$msg_model = new MsgConfig();
$dis = [
'uniacid' => $this->_uniacid
];
$data = $msg_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:14
* @功能说明:编辑配置
*/
public function msgConfigUpdate(){
$input = $this->_input;
$msg_model = new MsgConfig();
$dis = [
'uniacid' => $this->_uniacid
];
$data = $msg_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 11:58
* @功能说明:桌号列表
*/
public function tableList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$table_model = new Table();
$data = $table_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:21
* @功能说明:添加桌号
*/
public function tableAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$table_model = new Table();
$res = $table_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:23
* @功能说明:编辑桌号
*/
public function tableUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$table_model = new Table();
$res = $table_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:23
* @功能说明:桌号详情
*/
public function tableInfo(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$table_model = new Table();
$res = $table_model->dataInfo($dis);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-11-09 15:15
* @功能说明:刷新桌号码
*/
public function reTableQr(){
$input = $this->_input;
$qr_insert = [
'id' => $input['id']
];
$table_model = new Table();
$qr = $table_model->orderQr($qr_insert,$this->_uniacid);
if(!empty($qr)){
$table_model->dataUpdate(['id'=>$input['id']],['qr'=>$qr]);
}
return $this->success($qr);
}
/**
* @author chenniang
* @DataTime: 2021-12-30 11:51
* @功能说明:关于我们列表
*/
public function aboutUsList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
$dis[] = ['type','=',0];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$us_model = new AboutUs();
$data = $us_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:21
* @功能说明:添加我们列表
*/
public function aboutUsAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$us_model = new AboutUs();
$res = $us_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:23
* @功能说明:编辑我们列表
*/
public function aboutUsUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$us_model = new AboutUs();
$res = $us_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:23
* @功能说明:我们列表详情
*/
public function aboutUsInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id'],
];
$us_model = new AboutUs();
$res = $us_model->dataInfo($dis);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:23
* @功能说明:我们列表详情
*/
public function aboutUsInfoType(){
$input = $this->_param;
$input['type'] = !empty($input['type'])?$input['type']:0;
$dis = [
'type'=> $input['type'],
'uniacid' => $this->_uniacid
];
$us_model = new AboutUs();
$res = $us_model->dataInfo($dis);
if(!empty($input['type'])&&empty($res)){
$title = $input['type']==1?'动物认养协议':'土地租赁协议';
$dis['title'] = $title;
$us_model->dataAdd($dis);
$res = $us_model->dataInfo($dis);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-01-11 10:48
* @功能说明:配送配置详情
*/
public function sendConfigInfo(){
$dis = [
'uniacid' => $this->_uniacid
];
$config = $this->model->dataInfo($dis);
$send_model = new SendConfig();
$send_config = $send_model->where($dis)->select()->toArray();
$config['send_time'] = $send_config;
return $this->success($config);
}
/**
* @author chenniang
* @DataTime: 2022-01-11 11:51
* @功能说明:编辑配送设置
*/
public function sendConfigUpdate(){
$input = $this->_input;
$dis = [
'uniacid' => $this->_uniacid
];
$update = [
'app_day' => $input['app_day'],
// 'start_distance' => $input['start_distance'],
// 'start_price' => $input['start_price'],
//
// 'renew_distance' => $input['renew_distance'],
//
// 'renew_price' => $input['renew_price'],
];
$res = $this->model->dataUpdate($dis,$update);
$send_model = new SendConfig();
$send_model->where($dis)->delete();
if(!empty($input['send_time'])){
foreach ($input['send_time'] as $key => $value){
$input['send_time'][$key]['uniacid'] = $this->_uniacid;
}
$send_model->saveAll($input['send_time']);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:27
* @功能说明:公益栏目列表
*/
public function welfareList(){
$input = $this->_param;
$welfare_model = new WelfareColumn();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$type = !empty($input['type'])?$input['type']:1;
$dis[] = ['type','=',$type];
$data = $welfare_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-12 16:37
* @功能说明:添加公益栏目
*
*/
public function welfareAdd(){
$input = $this->_input;
$welfare_model = new WelfareColumn();
$input['uniacid'] = $this->_uniacid;
$res = $welfare_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:35
* @功能说明:编辑公益栏目
*/
public function welfareUpdate(){
$input = $this->_input;
$welfare_model = new WelfareColumn();
$dis = [
'id' => $input['id']
];
$res = $welfare_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:35
* @功能说明:公益栏目详情
*/
public function welfareInfo(){
$input = $this->_param;
$welfare_model = new WelfareColumn();
$dis = [
'id' => $input['id']
];
$res = $welfare_model->dataInfo($dis);
return $this->success($res);
}
}

View File

@@ -0,0 +1,190 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\BalanceCard;
use app\farm\model\BalanceOrder;
use app\farm\model\LandList;
use app\farm\model\Massif;
use app\farm\model\Source;
use app\farm\server\Land;
use think\App;
use think\facade\Db;
class AdminSource extends AdminRest
{
protected $model;
protected $massif_model;
protected $land_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new BalanceCard();
$this->massif_model = new Massif();
$this->land_model = new LandList();
}
/**
* @author chenniang
* @DataTime: 2021-12-14 17:04
* @功能说明:溯源列表
*/
public function sourceList(){
$input = $this->_param;
$source_model = new Source();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
$data = $source_model->dataList($dis,$input['limit']);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 17:04
* @功能说明:溯源下拉框
*/
public function sourceSelect(){
$input = $this->_param;
$source_model = new Source();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
if(!empty($input['farmer_id'])){
$dis[] = ['farmer_id','=',$input['farmer_id']];
}
$data = $source_model->where($dis)->select()->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 17:10
* @功能说明:添加溯源
*/
public function sourceAdd(){
$input = $this->_input;
$source_model = new Source();
$input['uniacid'] = $this->_uniacid;
$res = $source_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 17:12
* @功能说明:编辑溯源
*/
public function sourceUpdate(){
$input = $this->_input;
$source_model = new Source();
$input['uniacid'] = $this->_uniacid;
$dis = [
'id' => $input['id']
];
//删除
if(isset($input['status'])&&$input['status']==-1){
$find = $this->land_model->landSomeFind($input['id'],3);
if($find==1){
$this->errorMsg('该溯源正在被使用');
}
}
$res = $source_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-12-14 17:12
* @功能说明:编辑溯源
*/
public function sourceInfo(){
$input = $this->_param;
$source_model = new Source();
$dis = [
'id' => $input['id']
];
$res = $source_model->dataInfo($dis);
return $this->success($res);
}
}

View File

@@ -0,0 +1,852 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\farm\model\AdminRole;
use app\farm\model\BalanceWater;
use app\farm\model\Evaluate;
use app\farm\model\FinanceWater;
use app\farm\model\Node;
use app\farm\model\Role;
use app\massage\controller\Admin;
use app\massage\model\CarUserTrophy;
use app\massage\model\Commission;
use app\shop\model\Article;
use app\shop\model\Banner;
use app\shop\model\Date;
use app\massage\model\OrderGoods;
use app\massage\model\RefundOrder;
use app\shop\model\IntegralLog;
use app\shop\model\Wallet;
use think\App;
use app\farm\model\User as Model;
class AdminUser extends AdminRest
{
protected $model;
protected $order_goods_model;
protected $refund_order_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Model();
}
/**
* @author chenniang
* @DataTime: 2021-03-24 10:24
* @功能说明:用户列表
*/
public function userList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
//是否授权
if(!empty($input['type'])){
if($input['type']==1){
$dis[] = ['avatarUrl','=',''];
}else{
$dis[] = ['avatarUrl','<>',''];
}
}
if(isset($input['role'])){
$dis[] = ['role','=',$input['role']];
}
if(isset($input['is_black'])){
$dis[] = ['is_black','=',$input['is_black']];
}
$where = [];
if(!empty($input['nickName'])){
$where[] = ['nickName','like','%'.$input['nickName'].'%'];
$where[] = ['phone','like','%'.$input['nickName'].'%'];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$start_time = $input['start_time'];
$end_time = $input['end_time'];
$dis[] = ['create_time','between',"$start_time,$end_time"];
}
$data = $this->model->dataList($dis,$input['limit'],$where);
if(!empty($data['data'])){
$finance_model = new FinanceWater();
$water_model = new BalanceWater();
$inte_model = new IntegralLog();
foreach ($data['data'] as &$v){
$cash_data = $finance_model->getUserCashData($v['id']);
//总消费
$v['pay_cash'] = $cash_data['cash'];
//总退款
$v['refund_cash'] = $cash_data['refund_cash'];
//充值金额
$v['balance_cash']= $water_model->where(['type'=>1,'user_id'=>$v['id']])->sum('price');
//总积分
$v['total_integral'] = $inte_model->where(['user_id'=>$v['id']])->where('integral_add','>',0)->sum('integral_add');
//兑换积分
$v['pay_integral'] = round($v['total_integral']-$v['integral'],2);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-09-26 14:39
* @功能说明:编辑员工
*/
public function userUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$res = $this->model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-08-28 23:03
* @功能说明:佣金记录
*/
public function commList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
if(!empty($input['status'])){
$dis[] = ['a.status','=',$input['status']];
}
if(!empty($input['top_name'])){
$dis[] = ['c.nickName','like','%'.$input['top_name'].'%'];
}
$comm_model = new Commission();
$data = $comm_model->recordList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-09-26 15:02
* @功能说明:用户所有获得的奖杯
*/
public function userTrophy(){
$input = $this->_param;
$user_trophy_model = new CarUserTrophy();
$dis = [
'a.user_id' => $input['user_id'],
'a.status' => 1,
'b.status' => 1
];
$data = $user_trophy_model->alias('a')
->join('shequshop_car_trophy b','a.trophy_id = b.id')
->where($dis)
->field('a.*,b.title,b.cover')
->select()
->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-09-26 15:04
* @功能说明:用户添加奖杯
*/
public function userTrophyAdd(){
$input = $this->_input;
$user_trophy_model = new CarUserTrophy();
foreach ($input['user_id'] as $value){
foreach ($input['trophy_id'] as $v){
$dis = [
'user_id' => $value,
'trophy_id'=> $v,
'uniacid' => $this->_uniacid
];
$find = $user_trophy_model->where($dis)->where('status','>',-1)->find();
//增加
if($input['add']==1){
if(empty($find)){
$user_trophy_model->dataAdd($dis);
}
}else{
//减少
if(!empty($find)){
$user_trophy_model->dataUpdate($dis,['status'=>-1]);
}
}
}
}
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2022-02-10 13:32
* @功能说明:评价管理
*/
public function evaluateList(){
$input = $this->_param;
$eva_model = new Evaluate();
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.status','>',-1];
if(!empty($input['type'])){
$dis[] = ['a.type','=',$input['type']];
}
if(!empty($input['good'])){
$dis[] = ['a.star','>=',3];
}
if(!empty($input['bad'])){
$dis[] = ['a.star','<',3];
}
if(!empty($input['farmer_id'])){
$dis[] = ['a.farmer_id','=',$input['farmer_id']];
}
if(!empty($input['title'])){
$dis[] = ['b.title','line',"%".$input['title'].'%'];
}
$data = $eva_model->adminList($dis,$input['limit']);
$where[] = ['uniacid','=',$this->_uniacid];
$where[] = ['status','>',-1];
if(!empty($input['type'])){
$where[] = ['type','=',$input['type']];
}
$data['good_eva'] = $eva_model->where($where)->where('star','>=',3)->count();
$data['bad_eva'] = $eva_model->where($where)->where('star','<',3)->count();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-02-10 13:45
* @功能说明:编辑评论
*/
public function evaluateUpdate(){
$input = $this->_input;
$eva_model = new Evaluate();
$dis = [
'id' => $input['id']
];
$data = $eva_model->dataInfo($dis);
$res = $eva_model->dataUpdate($dis,$input);
if(!empty($input['status'])&&$input['status']==-1){
//修改农场主的评分
$res = $eva_model->updateFarmerStar($data['farmer_id']);
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:02
* @功能说明:角色列表
*/
public function roleList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$role_model = new Role();
$data = $role_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:02
* @功能说明:角色列表
*/
public function roleSelect(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
if(!empty($input['title'])){
$dis[] = ['title','like','%'.$input['title'].'%'];
}
$role_model = new Role();
$data = $role_model->where($dis)->select()->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 13:56
* @功能说明:添加角色
*/
public function roleAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$role_model = new Role();
$data = $role_model->dataAdd($input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:17
* @功能说明:编辑角色
*/
public function roleUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$input['uniacid'] = $this->_uniacid;
$role_model = new Role();
//删除
if(isset($input['status'])&&$input['status']==-1){
$adminRole_mdoel = new AdminRole();
$find = $adminRole_mdoel->alias('a')
->join('lbfarm_school_admin b','a.admin_id = b.id')
->where(['a.role_id'=>$input['id']])
->where('b.status','>',-1)
->find();
if(!empty($find)){
$this->errorMsg('该角色正在被使用');
}
}
$data = $role_model->dataUpdate($dis,$input);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:17
* @功能说明:角色详情
*/
public function roleInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$role_model = new Role();
$data = $role_model->dataInfo($dis);
$node_model = new Node();
$node = $node_model->where(['role_id'=>$input['id']])->select()->toArray();
if(!empty($node)){
foreach ($node as $k=>$v){
$node[$k]['auth'] = !empty($v['auth'])?explode(',',$v['auth']):[];
}
}
$data['node'] = $node;
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:18
* @功能说明:给账号分配角色(多选)
*/
public function adminRoleAdd(){
$input = $this->_input;
$adminRole_mdoel = new AdminRole();
$adminRole_mdoel->where(['admin_id'=>$input['admin_id']])->delete();
if(!empty($input['role'])){
foreach ($input['role'] as $key => $value){
$insert[$key] = [
'uniacid' => $this->_uniacid,
'admin_id'=> $input['admin_id'],
'role_id' => $value
];
}
$adminRole_mdoel->saveAll($insert);
}
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:24
* @功能说明:账号所匹配的角色详情
*/
public function adminInfo(){
$input = $this->_param;
$adminRole_mdoel = new AdminRole();
$admin_model = new \app\farm\model\Admin();
$dis= [
'id' => $input['id']
];
$data = $admin_model->dataInfo($dis);
$dis = [
'a.uniacid' => $this->_uniacid,
'b.status' => 1,
'a.admin_id'=> $input['id']
];
$data['role'] = $adminRole_mdoel->alias('a')
->join('lbfarm_role b','a.role_id = b.id')
->where($dis)
->field('b.*,a.role_id')
->group('b.id')
->select()
->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:24
* @功能说明:账号所匹配的角色的节点详情
*/
public function adminNodeInfo(){
$input = $this->_param;
$adminRole_mdoel = new AdminRole();
$data['is_admin'] = isset($this->_user['is_admin'])?$this->_user['is_admin']:1;
$dis = [
'a.uniacid' => $this->_uniacid,
'b.status' => 1,
'a.admin_id'=> $this->_user['id']
];
$data['node'] = $adminRole_mdoel->alias('a')
->join('lbfarm_role b','a.role_id = b.id')
->join('lbfarm_node c','c.role_id = b.id')
->where($dis)
->field('c.*')
->group('c.id')
->select()
->toArray();
if(!empty($data['node'])){
foreach ($data['node'] as $k=>$v){
$data['node'][$k]['auth'] = !empty($v['auth'])?explode(',',$v['auth']):[];
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:41
* @功能说明:账号列表
*/
public function adminList(){
$input = $this->_param;
$admin_model = new \app\farm\model\Admin();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
if(!empty($input['title'])){
$dis[] = ['username','like','%'.$input['title'].'%'];
}
$data = $admin_model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:47
* @功能说明:添加账号
*/
public function adminAdd(){
$input = $this->_input;
$admin_model = new \app\farm\model\Admin();
$dis = [
'uniacid' => $this->_uniacid,
'username'=> $input['username'],
];
$find = $admin_model->where($dis)->where('status','>',-1)->find();
if(!empty($find)){
$this->errorMsg('账号名不能重复');
}
$insert = [
'uniacid' => $this->_uniacid,
'username'=> $input['username'],
'o_passwd'=> $input['passwd'],
'passwd' => checkPass($input['passwd']),
'is_admin'=> 0,
];
$admin_model->dataAdd($insert);
$admin_id = $admin_model->getLastInsID();
$adminRole_mdoel = new AdminRole();
$adminRole_mdoel->where(['admin_id'=>$admin_id])->delete();
if(!empty($input['role'])){
foreach ($input['role'] as $key => $value){
$inserts[$key] = [
'uniacid' => $this->_uniacid,
'admin_id'=> $admin_id,
'role_id' => $value
];
}
$adminRole_mdoel->saveAll($inserts);
}
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2022-01-04 14:47
* @功能说明:添加账号
*/
public function adminUpdate(){
$input = $this->_input;
$admin_model = new \app\farm\model\Admin();
if(!empty($input['username'])){
$dis = [
'uniacid' => $this->_uniacid,
'username'=> $input['username'],
];
$find = $admin_model->where($dis)->where('status','>',-1)->where('id','<>',$input['id'])->find();
if(!empty($find)){
$this->errorMsg('账号名不能重复');
}
}
if(!empty($input['passwd'])){
$input['o_passwd'] = $input['passwd'];
$input['passwd'] = checkPass($input['passwd']);
}
$dis = [
'id' => $input['id']
];
if(isset($input['role'])){
$role = $input['role'];
unset($input['role']);
}
$admin_model->dataUpdate($dis,$input);
$adminRole_mdoel = new AdminRole();
$adminRole_mdoel->where(['admin_id'=>$input['id']])->delete();
if(!empty($role)){
foreach ($role as $key => $value){
$inserts[$key] = [
'uniacid' => $this->_uniacid,
'admin_id'=> $input['id'],
'role_id' => $value
];
}
$adminRole_mdoel->saveAll($inserts);
}
return $this->success(true);
}
/**
* @author chenniang
* @DataTime: 2022-07-20 16:00
* @功能说明:修改用户积分
*/
public function userIntegralUpdate(){
$input = $this->_input;
$log_model = new IntegralLog();
$type = $input['integral']>0?12:13;
$res = $log_model->integralUserAdd($input['user_id'],$input['integral'],$this->_uniacid,2,$type);
return $this->success($res);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,263 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\BalanceCard;
use app\farm\model\BalanceOrder;
use app\farm\model\BalanceWater;
use app\farm\model\User;
use app\Rest;
use app\shop\controller\IndexWxPay;
use longbingcore\wxcore\PayModel;
use think\App;
use think\Request;
class IndexBalance extends ApiRest
{
protected $model;
protected $article_model;
protected $coach_model;
protected $water_model;
protected $app;
public function __construct(App $app) {
parent::__construct($app);
$this->app = $app;
$this->model = new BalanceCard();
$this->balance_order = new BalanceOrder();
$this->water_model = new BalanceWater();
}
/**
* @author chenniang
* @DataTime: 2021-07-04 19:09
* @功能说明:储值充值卡列表
*/
public function cardList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
if(!empty($input['name'])){
$dis[] = ['title','like','%'.$input['name'].'%'];
}
$data = $this->model->dataList($dis,$input['limit']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-07 17:00
* @功能说明:充值余额
*/
public function payBalanceOrder(){
$input = $this->_input;
if(!empty($input['card_id'])){
$dis = [
'id' => $input['card_id'],
'status' => 1
];
$card = $this->model->dataInfo($dis);
if(empty($card)){
$this->errorMsg('充值卡已被下架');
}
}else{
$card = [
'price' => $input['price'],
'true_price' => $input['price'],
'id' => 0,
'integral' => 0,
'member_level'=> 0,
'title' => '自定义金额充值'
];
}
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'order_code' => orderCode(),
'pay_price' => $card['price'],
'sale_price' => $card['price'],
'true_price' => $card['true_price'],
'card_id' => $card['id'],
'title' => $card['title'],
'integral' => $card['integral'],
'pay_model' => $input['pay_model'],
'member_level'=> $card['member_level'],
//
// 'phone' => $input['phone']
];
$res = $this->balance_order->dataAdd($insert);
if($res==0){
$this->errorMsg('充值失败');
}
if($input['pay_model']==3){
$pay_model = new PayModel($this->payConfig());
$jsApiParameters = $pay_model->aliPay($insert['order_code'],$insert['pay_price'],'余额充值');
$arr['pay_list']= $jsApiParameters;
$arr['order_code']= $insert['order_code'];
}else{
//微信支付
$pay_controller = new IndexWxPay($this->app);
//支付
$jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"储值",['type' => 'Balance' , 'out_trade_no' => $insert['order_code']],$insert['pay_price']);
$arr['pay_list']= $jsApiParameters;
}
return $this->success($arr);
}
/**
* @author chenniang
* @DataTime: 2021-07-07 17:34
* @功能说明:充值订单列表
*/
public function balaceOrder(){
$input = $this->_param;
$dis[] = ['status','=',2];
$dis[] = ['user_id','=',$this->getUserId()];
if(!empty($input['start_time'])){
$dis[] = ['pay_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$data = $this->balance_order->dataList($dis);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
$v['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-07 18:00
* @功能说明:消费明细
*/
public function payWater(){
$input = $this->_param;
$dis[] = ['user_id','=',$this->getUserId()];
// $dis[] = ['type','=',2];
if(!empty($input['start_time'])){
$dis[] = ['create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$data = $this->water_model->dataList($dis);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
}
}
return $this->success($data);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,187 @@
<?php
namespace app\farm\controller;
use app\AdminRest;
use app\ApiRest;
use app\farm\model\BagAtv;
use app\farm\model\Coupon;
use app\farm\model\CouponAtv;
use app\farm\model\CouponAtvRecord;
use app\farm\model\CouponRecord;
use think\App;
use app\shop\model\Order as Model;
use think\facade\Db;
class IndexCoupon extends ApiRest
{
protected $model;
protected $atv_model;
protected $record_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Coupon();
$this->atv_model = new BagAtv();
$this->record_model = new CouponRecord();
}
/**
* @author chenniang
* @DataTime: 2022-03-02 11:07
* @功能说明:正在进行中的福包活动
*/
public function bagIngInfo(){
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
$dis[] = ['start_time','<',time()];
$dis[] = ['end_time','>',time()];
$data = $this->atv_model->dataInfo($dis);
if(empty($data)){
$this->errorMsg('活动已结束');
}
$where = [
'atv_id' => $data['id'],
'user_id'=> $this->getUserId(),
'status' => 1
];
//查看自己是否领取过
$user_record = $this->record_model->dataInfo($where);
if(!empty($user_record)){
//已经领取
$data['active_status'] = 2;
}elseif ($data['user_num']<$data['have_num']){
//已经领完
$data['active_status'] = 3;
}else{
//进行中
$data['active_status'] = 1;
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-02 13:44
* @功能说明:新客户获取活动优惠券
*/
public function getAtvCoupon(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$data = $this->atv_model->dataInfo($dis);
if(empty($data)){
$this->errorMsg('活动已结束');
}
$where = [
'atv_id' => $data['id'],
'user_id'=> $this->getUserId(),
'status' => 1
];
//查看自己是否领取过
$user_record = $this->record_model->dataInfo($where);
if(empty($user_record)){
$this->errorMsg('你已经领取过了');
}
//添加领取记录
Db::startTrans();
$insert = [
'uniacid' => $this->_uniacid,
'get_user' => $this->getUserId(),
'share_user'=> $input['share_user'],
'atv_id' => $data['id'],
'user_coupon'=> $data['user_coupon'],
'user_coupon_num'=> $data['user_coupon_num'],
'share_coupon'=> $data['share_coupon'],
];
$res = $this->record_model->dataAdd($insert);
if($res==0){
Db::rollback();
$this->errorMsg('领取失败');
}
$id = $this->record_model->getLastInsID();
$coupon_record_model = new CouponRecord();
//给新客户发优惠券
$res = $coupon_record_model->recordAdd($data['user_coupon'],$insert['get_user'],$id);
if(!empty($res['code'])){
Db::rollback();
$this->errorMsg($res['msg']);
}
Db::commit();
return $this->success($res);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,441 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\Farmer;
use app\farm\model\ShopGoods;
use app\farm\model\ShopGoodsCate;
use app\Rest;
use app\farm\model\Cap;
use app\farm\model\Car;
use app\farm\model\Goods;
use app\farm\model\GoodsCate;
use app\farm\model\User;
use app\shop\model\GoodsSpe;
use app\shop\model\GoodsSpePrice;
use app\shop\model\IntegralList;
use app\shop\model\OrderGoods;
use app\shop\model\SeckillList;
use app\shop\model\ShopGoodsSpe;
use app\shop\model\StoreGoods;
use think\App;
use think\Request;
class IndexGoods extends ApiRest
{
protected $model;
protected $cate_model;
protected $car_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new ShopGoods();
$this->cate_model = new ShopGoodsCate();
$this->car_model = new Car();
}
/**
* @author chenniang
* @DataTime: 2021-03-19 11:57
* @功能说明:首页选择店铺列表
*/
public function indexStoreList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',2];
$dis[] = ['business_status','=',1];
if(!empty($input['store_name'])){
$dis[] = ['title','like','%'.$input['store_name'].'%'];
}
$lat = !empty($input['lat'])?$input['lat']:0;
$lng = !empty($input['lng'])?$input['lng']:0;
$alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*('.$lat.'-lat)/360),2)+COS(3.1415926535898*'.$lat.'/180)* COS('.$lat.' * 3.1415926535898/180)*POW(SIN(3.1415926535898*('.$lng.'-lng)/360),2))))*1000 as distance';
$alhs = '(2 * 6378.137* ASIN(SQRT(POW(SIN(3.1415926535898*('.$lat.'-lat)/360),2)+COS(3.1415926535898*'.$lat.'/180)* COS('.$lat.' * 3.1415926535898/180)*POW(SIN(3.1415926535898*('.$lng.'-lng)/360),2))))*1000<20000';
$store_model = new Farmer();
$data = $store_model->dataDistanceList($dis,$alh,$alhs,10);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['distance'] = getDistances($v['lng'],$v['lat'],$lng,$lat);
$v['distance'] = $store_model->getDistanceAttr($v['distance']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 13:24
* @功能说明:选择门店
*/
public function selectStore(){
$input = $this->_input;
$user_model = new User();
$res = $user_model->dataUpdate(['id'=>$this->getUserId()],['last_store_id'=>$input['store_id']]);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-18 16:46
* @功能说明:分类列表
*/
public function goodsIndex(){
$input = $this->_param;
$store_id = !empty($input['store_id'])?$input['store_id']:0;
$data['cate_id'] = $this->cate_model->shopCateList($this->_uniacid,$store_id);
if(!empty($store_id)){
$store_model = new Farmer();
$data['store_info'] = $store_model->dataInfo(['id'=>$store_id]);
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 13:47
* @功能说明:
*/
public function haveSelectStoreId(){
return $this->success($this->getStoreInfo()['id']);
}
/**
* @author chenniang
* @DataTime: 2022-02-22 15:27
* @功能说明:商品列表
*/
public function goodsList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.status','=',1];
// $dis[] = ['a.index_show','=',1];
$dis[] = ['d.status','=',2];
$dis[] = ['d.business_status','=',1];
if(!empty($input['store_id'])){
$dis[] = ['b.store_id','=',$input['store_id']];
}
if(!empty($input['cate_id'])){
$dis[] = ['c.cate_id','=',$input['cate_id']];
}
if(!empty($input['goods_name'])){
$dis[] = ['a.goods_name','like','%'.$input['goods_name'].'%'];
}
//商品信息
$data = $this->model->indexGoodsList($dis,10);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$where = [
'type' => 5,
'user_id' => $this->getUserId()
];
$v['car_count'] = $this->car_model->where($where)->count();
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:46
* @功能说明:商品详情
*/
public function goodsInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->model->dataInfo($dis);
$farm_model = new Farmer();
$where[] = ['id','in',$data['store']];
$data['store_info'] = $farm_model->dataInfo($where);
$spe_model = new ShopGoodsSpe();
$spe_price_model = new GoodsSpePrice();
$where = [
'goods_id' => $input['id'],
'status' => 1
];
$data['spe_text'] = $spe_model->goodsSpe($where);
$data['spe_price'] = $spe_price_model->goodsSpePrice($where);
$kill_model = new SeckillList();
$integral_model = new IntegralList();
//秒杀活动
$data['kill_list'] = $kill_model->atvIng($input['id'],0,2);
if(!empty($data['spe_price'])){
foreach ($data['spe_price'] as &$v){
//查询是否有秒杀活动
$v['kill_atv'] = $kill_model->atvIng($input['id'],$v['id']);
if(empty($v['kill_atv'])){
//积分活动
$v['integral_atv'] = $integral_model->atvIng($input['id'],$v['id']);
}else{
$v['integral_atv'] = [];
}
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:07
* @功能说明:购物车信息
*/
public function carInfo(){
$input = $this->_param;
$store_id = !empty($input['store_id'])?$input['store_id']:0;
//购物车信息
$car_info = $this->car_model->carPriceAndCount($this->getUserId(),$store_id,1);
return $this->success($car_info);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:46
* @功能说明:添加到购物车
*/
public function addCar(){
$input = $this->_input;
$is_show_del = !empty($input['is_show_del'])?$input['is_show_del']:1;
if($is_show_del==1){
$this->car_model->where(['user_id'=>$this->getUserId(),'is_show'=>2])->delete();
}
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'farmer_id'=> $input['store_id'],
'goods_id'=> $input['goods_id'],
'spe_id' => $input['spe_id'],
'type' => 5,
'is_show' => !empty($input['is_show'])?$input['is_show']:1,
];
$input['goods_num'] = !empty($input['goods_num'])?$input['goods_num']:1;
$info = $this->car_model->dataInfo($insert);
//增加数量
if(!empty($info)){
$res = $this->car_model->dataUpdate(['id'=>$info['id']],['goods_num'=>$info['goods_num']+$input['goods_num']]);
}else{
//添加到购物车
$insert['goods_num'] = $input['goods_num'];
$insert['status'] = 1;
$res = $this->car_model->dataAdd($insert);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:54
* @功能说明:删除购物车
*/
public function delCar(){
$input = $this->_input;
$info = $this->car_model->dataInfo(['id'=>$input['id']]);
$input['goods_num'] = !empty($input['goods_num'])?$input['goods_num']:1;
//加少数量
if($info['goods_num']>$input['goods_num']){
$res = $this->car_model->dataUpdate(['id'=>$info['id']],['goods_num'=>$info['goods_num']-$input['goods_num']]);
}else{
$res = $this->car_model->where(['id'=>$info['id']])->delete();
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 10:39
* @功能说明:
*/
public function carUpdate(){
$input = $this->_input;
if(!empty($input['id'])){
$res = $this->car_model->where('id','in',$input['id'])->update(['status'=>$input['status']]);
}else{
$res = $this->car_model->where('user_id','=',$this->getUserId())->update(['status'=>$input['status']]);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:59
* @功能说明:批量删除购物车
*/
public function delSomeCar(){
$input = $this->_input;
$dis = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'farmer_id'=> $this->getStoreInfo()['id'],
'type' => 5,
];
$res = $this->car_model->where($dis)->delete();
return $this->success($res);
}
}

View File

@@ -0,0 +1,148 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\Config;
use app\farm\model\FinanceWater;
use app\farm\model\InfoRecord;
use app\farm\model\SystemInfo;
use app\farm\model\User;
use app\farm\model\Wallet;
use app\farm\model\WelfareColumn;
use app\shop\model\DistributionCash;
use app\shop\model\DistributionList;
use think\App;
use think\facade\Db;
use think\Request;
class IndexInfo extends ApiRest
{
protected $model;
protected $user_model;
protected $cash_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new SystemInfo();
$this->info_model = new WelfareColumn();
$this->record_model = new InfoRecord();
}
/**
* @author chenniang
* @DataTime: 2022-08-22 15:13
* @功能说明:查看自己的系统公告
*/
public function systemInfoList(){
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['user_id','=',$this->getUserId()];
$count = $this->model->where($dis)->where(['status'=>0])->count();
$this->model->where($dis)->where(['status'=>0])->update(['status'=>1]);
$dis[] = ['status','>',-1];
$data = $this->model->dataList($dis);
$data['no_read_count'] = $count;
$data['operate_no_read_count'] = $this->record_model->noReadCount($this->getUserId(),$this->_uniacid);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-08-22 15:54
* @功能说明:运营公告
*/
public function operateInfoList(){
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['type','=',3];
$dis[] = ['status','=',1];
$data = $this->info_model->dataList($dis);
//未读消息数量
$data['operate_no_read_count'] = $this->record_model->noReadCount($this->getUserId(),$this->_uniacid);
$where[] = ['uniacid','=',$this->_uniacid];
$where[] = ['user_id','=',$this->getUserId()];
$data['no_read_count'] = $this->model->where($where)->where(['status'=>0])->count();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-08-22 16:16
* @功能说明:运营公告详情
*/
public function operateInfoInfo(){
$input = $this->_param;
$data = $this->info_model->dataInfo(['id'=>$input['id']]);
$insert = [
'user_id' => $this->getUserId(),
'uniacid' => $this->_uniacid,
'info_id' => $input['id']
];
$find = $this->record_model->dataInfo($insert);
if(empty($find)){
$this->record_model->dataAdd($insert);
}
return $this->success($data);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,959 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\Coupon;
use app\farm\model\CouponRecord;
use app\farm\model\Evaluate;
use app\farm\model\Farmer;
use app\farm\model\ShopOrder;
use app\farm\model\ShopOrderGoods;
use app\farm\model\ShopRefund;
use app\publics\model\TmplConfig;
use app\farm\model\Address;
use app\farm\model\Car;
use app\farm\model\Config;
use app\farm\model\Goods;
use app\farm\model\MsgConfig;
use app\farm\model\Order;
use app\farm\model\OrderAddress;
use app\farm\model\OrderGoods;
use app\farm\model\RefundOrder;
use app\shfarmop\model\User;
use app\shop\controller\IndexWxPay;
use app\shop\model\SeckillList;
use longbingcore\wxcore\PayModel;
use think\App;
use think\facade\Db;
use think\Request;
class IndexOrder extends ApiRest
{
protected $model;
protected $refund_model;
protected $order_goods_model;
protected $app;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new ShopOrder();
$this->app = $app;
$this->refund_model = new ShopRefund();
$this->order_goods_model = new ShopOrderGoods();
autoCancelOrder($this->_uniacid);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:48
* @功能说明:个人中心
*/
public function orderList(){
//超时自动取消订单
$this->model->autoCancelOrder($this->_uniacid,$this->getUserId());
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.user_id','=',$this->getUserId()];
$where = [];
if(!empty($input['name'])){
$where[] = ['b.goods_name','like','%'.$input['name'].'%'];
$where[] = ['a.order_code','like','%'.$input['name'].'%'];
}
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}
$data = $this->model->indexDataList($dis,$where);
$eva_model = new Evaluate();
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$can_refund_num = is_array($v['order_goods'])?array_sum(array_column($v['order_goods'],'can_refund_num')):0;
if(!empty($v['add_price'])&&$v['add_price_refund']==0){
$can_refund_num+=1;
}
//是否可以申请退款
if(($v['pay_type']==7&&$v['can_refund_time']>time()&&$can_refund_num>0)||($v['pay_type']==2&&$can_refund_num>0)){
$v['can_refund'] = 1;
}else{
$v['can_refund'] = 0;
}
$dis = [
'user_id' => $this->getUserId(),
'order_id'=> $v['id'],
'type' => 3
];
$have_eva = $eva_model->where($dis)->where('status','>',-1)->find();
//是否已经评价
$v['have_eva'] = !empty($have_eva)?1:0;
}
}
$arr = [
//未支付
'no_pay_count' => 1,
//未发货
'no_send_count' => 2,
//已经发货
'have_send_count'=> 3
];
foreach ($arr as $ks=>$vs){
$map = [
'user_id' => $this->getUserId(),
'pay_type'=> $vs
];
$data[$ks] = $this->model->where($map)->count();
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-15 14:58
* @功能说明:订单详情
*/
public function orderInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->model->dataInfo($dis);
$data['over_time'] -= time();
$time_arr = ['create_time','pay_time','end_time','hx_time','cancel_time'];
foreach ($time_arr as $v){
$data[$v] = !empty($data[$v])?date('Y-m-d H:i:s',$data[$v]):$data[$v];
}
$data['distance'] = distance_text($data['distance']);
$end_time = date('H:i',$data['send_end_time'])=='00:00'?'24:00':date('H:i',$data['send_end_time']);
//配送时间
$data['user_send_time'] = date('Y-m-d H:i',$data['send_start_time']).'~'.$end_time;
//剩余可申请退款数量
$can_refund_num = array_sum(array_column($data['order_goods'],'can_refund_num'));
//是否可以申请退款
if(($data['pay_type']==7&&$data['can_refund_time']>time()&&$can_refund_num>0)||($data['pay_type']==2&&$can_refund_num>0)){
$data['can_refund'] = 1;
}else{
$data['can_refund'] = 0;
}
$farmer_model = new Farmer();
$data['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['farmer_id']],'title');
$dis = [
'user_id' => $this->getUserId(),
'order_id'=> $data['id'],
'type' => 3
];
$eva_model = new Evaluate();
$have_eva = $eva_model->where($dis)->where('status','>',-1)->find();
//是否已经评价
$data['have_eva'] = !empty($have_eva)?1:0;
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 17:29
* @功能说明:退款订单详情
*
*/
public function refundOrderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.user_id','=',$this->getUserId()];
$where = [];
if(!empty($input['name'])){
$where[] = ['b.goods_name','like','%'.$input['name'].'%'];
$where[] = ['a.order_code','like','%'.$input['name'].'%'];
}
if(!empty($input['status'])){
$dis[] = ['a.status','=',$input['status']];
}else{
$dis[] = ['a.status','>',-1];
}
$data = $this->refund_model->indexDataList($dis,$where);
$map = [
'status' => 1,
'user_id'=> $this->getUserId()
];
//退款中数量
$data['ing_count'] = $this->refund_model->where($map)->count();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 17:50
* @功能说明:退款订单详情
*/
public function refundOrderInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->refund_model->dataInfo($dis);
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
$data['refund_time'] = date('Y-m-d H:i:s',$data['refund_time']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-09-01 16:08
* @功能说明:配送方式
*/
public function goodsSendType(){
$input = $this->_param;
$car_model = new Car();
$is_show = isset($input['is_show'])?$input['is_show']:1;
$list = $car_model->carList($this->getUserId(),1,0,$is_show);
$data['is_self'] = 0;
$data['is_send'] = 0;
if(!empty($list)){
foreach ($list as &$value){
$data['is_self'] = !empty($value['is_self'])?$value['is_self']:$data['is_self'];
$data['is_send'] = !empty($value['is_send'])?$value['is_send']:$data['is_send'];
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-22 09:43
* @功能说明:下单页面详情
*/
public function payOrderInfo(){
$input = $this->_param;
$coupon_id = isset($input['coupon_id'])?$input['coupon_id']:0;
$is_show = isset($input['is_show'])?$input['is_show']:1;
$send_type = isset($input['send_type'])?$input['send_type']:2;
$no_i = isset($input['no_i'])?$input['no_i']:1;
$address_model = new Address();
$defult_address = $address_model->dataInfo(['user_id'=>$this->getUserId(),'status'=>1]);
$defult_address_id = !empty($defult_address)?$defult_address['id']:0;
$address_id = !empty($input['address_id'])?$input['address_id']:$defult_address_id;
$order_info = $this->model->payOrderInfo($this->getUserId(),0,$coupon_id,$address_id,$is_show,$send_type,$no_i);
if(!empty($input['address_id'])){
//默认地址
$order_info['address'] = $address_model->dataInfo(['id'=>$input['address_id']]);
}else{
$order_info['address'] = $defult_address;
}
$coupon_modle = new Coupon();
$coupon_record_model = new CouponRecord();
//可用优惠券数量
$canUseCoupon = $coupon_modle->canUseCoupon($this->getUserId(),$order_info['goods_price']);
$order_info['canUseCoupon'] = $coupon_record_model->where('id','in',$canUseCoupon)->sum('num');
//模版消息model
$tmpl_model = new TmplConfig();
//获取模版
$data['tmp_list'] = $tmpl_model->where(['uniacid'=>$this->_uniacid])->where('tmpl_name','in',['shop_order','send_over'])->select()->toArray();
return $this->success($order_info);
}
/**
* @author chenniang
* @DataTime: 2021-03-22 09:53
* @功能说明:下单
*/
public function payOrder(){
$input = $this->_input;
$send_type = isset($input['send_type'])?$input['send_type']:2;
$coupon_id = !empty($input['coupon_id'])?$input['coupon_id']:0;
$address_id = isset($input['address_id'])?$input['address_id']:0;
$is_show = isset($input['is_show'])?$input['is_show']:1;
$no_i = isset($input['no_i'])?$input['no_i']:1;
$order_info = $this->model->payOrderInfo($this->getUserId(),0,$coupon_id,$address_id,$is_show,$send_type,$no_i);
$config_model = new Config();
$address_order_model = new OrderAddress();
$config = $config_model->dataInfo(['uniacid'=>$this->_uniacid]);
$top_order_code = orderCode();
$kill_model = new SeckillList();
//校验秒杀活动
$res = $kill_model->userCheck($this->getUserId(),$order_info['kill_atv_id'],$is_show);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
Db::startTrans();
//按农场主生成多个订单
foreach ($order_info['order_goods'] as $value){
$order_insert = [
'uniacid' => $this->_uniacid,
'order_code' => orderCode(),
'top_order_code' => $top_order_code,
'user_id' => $this->getUserId(),
'pay_price' => $value['pay_price'],
'get_integral'=> $value['pay_price'],
'true_price' => $value['pay_price'],
'pay_type' => 1,
'goods_price'=> $value['goods_price'],
'farmer_id' => $value['farmer_id'],
'store_id' => $value['farmer_id'],
'init_price' => $value['init_price'],
'init_goods_price' => $value['init_goods_price'],
'text' => $input['text'],
'over_time' => !empty($order_info['kill_atv_id'])?time()+$order_info['kill_over_time']*60:time()+$config['over_time']*60,
'send_type' => $send_type,
'discount' => $value['coupon_discount'],
'freight' => $value['freight'],
'distance' => $value['distance'],
'balance' => $input['pay_model']==2?$value['pay_price']:0,
'total_price' => $order_info['pay_price'],
'send_start_time' => $input['start_time'],
'send_end_time' => $input['end_time'],
'pay_model' => $input['pay_model'],
'kill_atv_id' => $order_info['kill_atv_id'],
'kill_discount_price' => $value['kill_discount_price'],
'integral' => $no_i==0?$value['integral']:0,
'integral_discount_price' => $no_i==0?$value['integral_discount_price']:0,
];
//下单
$res = $this->model->dataAdd($order_insert);
if($res!=1){
Db::rollback();
$this->errorMsg('下单失败');
}
$order_id = $this->model->getLastInsID();
//添加下单地址
$res = $address_order_model->orderAddressAdd($input['address_id'],$order_id,$send_type,5,$input);
if(!empty($res['code'])){
Db::rollback();
$this->errorMsg($res['msg']);
}
$order_insert['id'] = $order_id;
if(empty($order_info['order_goods'])){
$this->errorMsg('订单错误');
}
//添加到子订单
$res = $this->order_goods_model->orderGoodsAdd($value['goods_list'],$order_id,$this->getUserId(),$value['farmer_id'],$input['address_id']);
if(!empty($res['code'])){
Db::rollback();
$this->errorMsg($res['msg']);
}
//使用优惠券
if(!empty($order_info['coupon_id'])){
$this->model->dataUpdate(['id'=>$order_id],['coupon_id'=>$coupon_id]);
}
//积分活动
$res = $this->model->marketingCheck($order_insert,$value['goods_list']);
if(!empty($res['code'])){
Db::rollback();
$this->errorMsg($res['msg']);
}
}
//使用优惠券
if(!empty($order_info['coupon_id'])){
$coupon_record_model = new CouponRecord();
$coupon_record_model->couponUse($order_info['coupon_id']);
}
Db::commit();
//如果是0元
if($order_info['pay_price']<=0){
$this->model->orderResult($top_order_code,$top_order_code);
return $this->success(true);
}
//余额支付
if($input['pay_model']==2){
$user_model = new \app\farm\model\User();
$user_balance= $user_model->where(['id'=>$this->getUserId()])->value('balance');
if($user_balance<$order_info['pay_price']){
$this->errorMsg('余额不足');
}
$this->model->orderResult($top_order_code,$top_order_code);
return $this->success(true);
}elseif ($input['pay_model']==3){
$pay_model = new PayModel($this->payConfig());
$jsApiParameters = $pay_model->aliPay($top_order_code,$order_info['pay_price'],'商场商品');
$arr['pay_list']= $jsApiParameters;
$arr['order_code']= $order_insert['order_code'];
}else{
//微信支付
$pay_controller = new IndexWxPay($this->app);
//支付
$jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"商城",['type' => 'SchoolShop' , 'out_trade_no' => $top_order_code],$order_info['pay_price']);
$arr['pay_list']= $jsApiParameters;
}
return $this->success($arr);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 15:59
* @功能说明:重新支付
*/
public function rePayOrder(){
$input = $this->_input;
$order_insert = $this->model->dataInfo(['id'=>$input['id']]);
if($order_insert['pay_type']!=1){
$this->errorMsg('订单状态错误');
}
//余额支付
if($order_insert['pay_model']==2){
$user_model = new \app\massage\model\User();
$user_balance= $user_model->where(['id'=>$this->getUserId()])->value('balance');
if($user_balance<$order_insert['pay_price']){
$this->errorMsg('余额不足');
}
$this->model->orderResult($order_insert['order_code'],$order_insert['order_code']);
return $this->success(true);
}elseif ($order_insert['pay_model']==3){
$pay_model = new PayModel($this->payConfig());
$jsApiParameters = $pay_model->aliPay($order_insert['order_code'],$order_insert['pay_price'],'商场商品');
$arr['pay_list']= $jsApiParameters;
$arr['order_code']= $order_insert['order_code'];
}else{
//微信支付
$pay_controller = new IndexWxPay($this->app);
//支付
$jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"商城",['type' => 'SchoolShop' , 'out_trade_no' => $order_insert['order_code']],$order_insert['pay_price']);
$arr['pay_list']= $jsApiParameters;
}
return $this->success($arr);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 16:38
* @功能说明:取消订单
*/
public function cancelOrder(){
$input = $this->_input;
$order_insert = $this->model->dataInfo(['id'=>$input['id']]);
if($order_insert['pay_type']!=1){
$this->errorMsg('订单状态错误');
}
$res = $this->model->cancelOrder($order_insert);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-26 11:39
* @功能说明:申请退款
*/
public function applyOrder(){
$input = $this->_input;
$order = $this->model->dataInfo(['id'=>$input['order_id']]);
if(empty($order)){
$this->errorMsg('订单未找到');
}
if($order['pay_type']<2&&$order['have_tx']!=0){
$this->errorMsg('订单状态错误');
}
if(empty($input['list'])){
$this->errorMsg('请选择商品');
}
if($order['can_refund_time']<time()&&$order['pay_type']==7){
$this->errorMsg('核销后24小时内才能申请退款哦');
}
//申请退款
$res = $this->refund_model->applyRefund($order,$input);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-26 15:55
* @功能说明:取消退款
*/
public function cancelRefundOrder(){
$input = $this->_input;
$order = $this->refund_model->dataInfo(['id'=>$input['id']]);
if($order['status']!=1){
$this->errorMsg('订单已经审核');
}
Db::startTrans();
$res = $this->refund_model->dataUpdate(['id'=>$input['id']],['status'=>-1,'cancel_time'=>time()]);
if($res!=1){
Db::rollback();
$this->errorMsg('取消失败');
}
if(!empty($order['order_goods'])){
$order_goods_model = new ShopOrderGoods();
foreach ($order['order_goods'] as $v){
if(!empty($v['order_goods_id'])){
$num = $v['goods_num'];
$res = $order_goods_model->where(['id'=>$v['order_goods_id']])->update(['can_refund_num'=>Db::Raw("can_refund_num+$num")]);
if($res!=1){
Db::rollback();
$this->errorMsg('取消失败');
}
}else{
$this->model->dataUpdate(['id'=>$order['order_id']],['add_price_refund'=>0]);
}
}
}
Db::commit();
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-04-07 15:30
* @功能说明:刷新订单二维码
*/
public function refreshQr(){
$input = $this->_input;
$qr_insert = [
'id' => $input['id']
];
//获取二维码
$qr = $this->model->orderQr($qr_insert,$this->_uniacid);
if(!empty($qr)){
$this->model->dataUpdate(['id'=>$input['id']],['qr'=>$qr]);
}
return $this->success($qr);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 17:14
* @功能说明:楼长核销订单
*/
public function endOrder(){
$input = $this->_input;
$order_model= new ShopOrder();
$order = $order_model->dataInfo(['id'=>$input['id']]);
if(empty($order)){
$this->errorMsg('订单未找到');
}
if(empty($order)){
$this->errorMsg('订单未找到');
}
//自提
if($order['send_type']==1&&$order['pay_type']!=2){
$this->errorMsg('订单状态错误');
}
//快递
if($order['send_type']==2&&$order['pay_type']!=3){
$this->errorMsg('订单状态错误');
}
$refund_model = new ShopRefund();
//判断有无申请中的退款订单
$refund_order = $refund_model->dataInfo(['order_id'=>$order['id'],'status'=>1]);
if(!empty($refund_order)){
$this->errorMsg('该订单正在申请退款,请先处理再核销');
}
$res = $order_model->hxOrder($input['id'],$this->getUserId());
return $this->success($res);
}
public function getPayNumber(){
$input = $this->_input;
$number= $this->order_goods_model->getGoodsNumber(['a.goods_id'=>$input['id'],'b.user_id'=>$this->getUserId()] );
return $this->success(['number'=>$number]);
}
/**
* @author chenniang
* @DataTime: 2021-07-10 00:40
* @功能说明:可用的优惠券列表
*/
public function couponList(){
$input = $this->_param;
$coupon_model = new Coupon();
$coupon_record_model = new CouponRecord();
$is_show = isset($input['is_show'])?$input['is_show']:1;
$send_type = isset($input['send_type'])?$input['send_type']:2;
$no_i = isset($input['no_i'])?$input['no_i']:1;
$order_info = $this->model->payOrderInfo($this->getUserId(),0,0,0,$is_show,$send_type,$no_i);
$coupon_id = $coupon_model->canUseCoupon($this->getUserId(),$order_info['goods_price'],1);
$data = $coupon_record_model->where('id','in',$coupon_id)->order('id desc')->paginate(10)->toArray();
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['start_time'] = date('Y.m.d H:i',$v['start_time']).' - '.date('Y.m.d H:i',$v['end_time']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-11-16 14:42
* @功能说明:订阅消息通知
*/
public function tmplList(){
$tmpl_model = new TmplConfig();
$dis = [
'uniacid' => $this->_uniacid
];
$data = $tmpl_model->where($dis)->select()->toArray();
return $this->success($data);
}
}

View File

@@ -0,0 +1,259 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\Config;
use app\farm\model\FinanceWater;
use app\farm\model\User;
use app\farm\model\Wallet;
use app\shop\model\DistributionCash;
use app\shop\model\DistributionList;
use think\App;
use think\facade\Db;
use think\Request;
class IndexReseller extends ApiRest
{
protected $model;
protected $user_model;
protected $cash_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new DistributionList();
$this->user_model = new User();
$this->cash_model = new DistributionCash();
$dis = [
'status' => 2,
'user_id'=> $this->getUserId()
];
$reseller = $this->model->dataInfo($dis);
if(empty($reseller)){
$this->errorMsg('你还不是分销商');
}
}
/**
* @author chenniang
* @DataTime: 2022-02-22 13:53
* @功能说明:分销中心
*/
public function resellerInfo(){
$user = $this->user_model->dataInfo(['id'=>$this->getUserId()],'id,nickName,avatarUrl,fx_code,fx_cash');
if(empty($user['fx_code'])){
$user['fx_code'] = getCardCode();
$this->user_model->dataUpdate(['id'=>$user['id']],['fx_code'=>$user['fx_code']]);
}
$dis = [
'user_id' => $this->getUserId(),
'status' => 1
];
$user['notreceived_cash'] = $this->cash_model->where($dis)->sum('cash');
$wallet_model = new Wallet();
$user['wallet_price'] = $wallet_model->where(['user_id'=>$this->getUserId(),'type'=>5])->where('status','in',[1,2])->sum('pay_price');
return $this->success($user);
}
/**
* @author chenniang
* @DataTime: 2022-07-27 18:00
* @功能说明:订单列表
*/
public function orderList(){
$input = $this->_param;
$dis[] = ['user_id','=',$this->getUserId()];
if(!empty($input['status'])){
$dis[] = ['status','=',$input['status']];
}else{
$dis[] = ['status','>',-1];
}
if(!empty($input['type'])){
$dis[] = ['type','=',$input['type']];
}
$data = $this->cash_model->dataList($dis);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['source_info'] = $this->user_model->where(['id'=>$v['source_id']])->field('nickName,avatarUrl')->find();
$v['order_price'] = array_sum(array_column($v['order_goods'],'pay_price'));
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-28 14:23
* @功能说明:我的团队
*/
public function myTeam(){
$input = $this->_param;
$data = $this->model->myTeam($this->getUserId(),$input['type']);
$data['one_count'] = $this->model->teamCount($this->getUserId());
$data['two_count'] = $this->model->teamCount($this->getUserId(),2);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-30 11:15
* @功能说明:申请提现
*/
public function applyWallet(){
$input = $this->_input;
$wallet_model = new Wallet();
$user = $this->user_model->dataInfo(['id'=>$this->getUserId()]);
if($input['apply_price']>$user['fx_cash']){
$this->errorMsg('余额不足');
}
Db::startTrans();
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'order_code' => orderCode(),
'farmer_id' => 0,
'pay_price' => $input['apply_price'],
'text' => $input['text'],
'true_price' => round($input['apply_price'],2),
'balance' => 100,
'type' => 5
];
//发起提现
$res = $wallet_model->dataAdd($insert);
if($res==0){
Db::rollback();
$this->errorMsg('申请失败');
}
$res = $this->user_model->dataUpdate(['id'=>$this->getUserId(),'fx_cash'=>$user['fx_cash']],['fx_cash'=>$user['fx_cash']-$input['apply_price']]);
if($res==0){
Db::rollback();
$this->errorMsg('申请失败');
}
Db::commit();
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-07-28 15:02
* @功能说明:提现记录
*/
public function walletList(){
$input = $this->_param;
$dis = [
'user_id' => $this->getUserId(),
'type' => 5
];
if(!empty($input['status'])){
$dis['status'] = $input['status'];
}
$wallet_model = new Wallet();
$data = $wallet_model->dataList($dis);
return $this->success($data);
}
}

View File

@@ -0,0 +1,963 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\Breed;
use app\farm\model\BreedOrder;
use app\farm\model\Claim;
use app\farm\model\ClaimOrder;
use app\farm\model\ClaimText;
use app\farm\model\Config;
use app\farm\model\Evaluate;
use app\farm\model\FinanceWater;
use app\farm\model\Goods;
use app\farm\model\GoodsCate;
use app\farm\model\GoodsSh;
use app\farm\model\LandCate;
use app\farm\model\LandList;
use app\farm\model\LandOrder;
use app\farm\model\LandSourceText;
use app\farm\model\LandSpe;
use app\farm\model\LandText;
use app\farm\model\Machine;
use app\farm\model\Massif;
use app\farm\model\Address;
use app\farm\model\Farmer;
use app\farm\model\Monitor;
use app\farm\model\MonitorText;
use app\farm\model\Seed;
use app\farm\model\SendOrder;
use app\farm\model\ShopGoods;
use app\farm\model\ShopGoodsCate;
use app\farm\model\ShopGoodsSh;
use app\farm\model\ShopOrder;
use app\farm\model\Source;
use app\farm\model\SourceText;
use app\farm\model\User;
use app\farm\model\Wallet;
use app\farm\model\ShopRefund;
use longbingcore\wxcore\WxSetting;
use think\App;
use think\facade\Db;
use think\Request;
class IndexStore extends ApiRest
{
protected $model;
protected $address_model;
protected $massif_model;
protected $land_model;
protected $user_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new Farmer();
$this->user_model = new User();
$dis = [
'type' => 2,
'status' => 2,
'user_id'=> $this->getUserId()
];
$this->store = $this->model->dataInfo($dis);
if(empty($this->store)){
$this->errorMsg('你还不是地主');
}
$this->address_model = new Address();
$this->land_model = new LandList();
$this->massif_model = new Massif();
}
/**
* @author chenniang
* @DataTime: 2022-02-22 13:53
* @功能说明:店铺详情
*/
public function storeInfo(){
return $this->success($this->store);
}
/**
* @author chenniang
* @DataTime: 2022-02-22 13:54
* @功能说明:修改店铺
*/
public function storeUpdate(){
$input = $this->_input;
$dis = [
'id' => $this->store['id']
];
$res = $this->model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 09:34
* @功能说明:商品分类列表
*/
public function goodsCateList(){
$cate_model = new ShopGoodsCate();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','>',-1];
$dis[] = ['store_id','=',$this->store['id']];
$data = $cate_model->dataList($dis,20);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 10:03
* @功能说明:添加商品分类
*/
public function goodsCateAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$input['store_id'] = $this->store['id'];
$cate_model = new ShopGoodsCate();
$res = $cate_model->dataAdd($input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 10:06
* @功能说明:编辑商品分类
*/
public function goodsCateUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$cate_model = new ShopGoodsCate();
$cate_info = $cate_model->dataInfo($dis);
if(empty($cate_info)){
$this->errorMsg('商品分类不存在');
}
//如果是删除
if(!empty($input['status'])&&$input['status']==-1&&$cate_info['goods_num']>0){
$this->errorMsg('该分类下存在商品,无法删除');
}
$res = $cate_model->dataUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 10:08
* @功能说明:商品分类下拉框
*/
public function goodsCateSelect(){
$cate_model = new ShopGoodsCate();
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['status','=',1];
$dis[] = ['store_id','=',$this->store['id']];
$data = $cate_model->where($dis)->where('top desc,id desc')->select()->toArray();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 15:06
* @功能说明:商品各个状态下的数量
*/
public function goodsCount(){
$dis = [
'uniacid' => $this->_uniacid,
'store_id' => $this->store['id'],
'status' => 1
];
$goods_model = new ShopGoods();
//上架数量
$data['on_count'] = $goods_model->where($dis)->count();
$dis['status'] = 2;
//下架数量
$data['off_count'] = $goods_model->where($dis)->count();
$dis['status'] = 3;
//仓库数量
$data['house_count'] = $goods_model->where($dis)->count();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 11:08
* @功能说明:商品列表
*/
public function goodsList(){
$input = $this->_param;
$dis[] = ['uniacid','=',$this->_uniacid];
$dis[] = ['store_id','=',$this->store['id']];
$dis[] = ['status','=',$input['status']];
//商品名字搜索
if(!empty($input['goods_name'])){
$dis[] = ['goods_name','like','%'.$input['goods_name'].'%'];
}
$goods_model = new ShopGoods();
$data = $goods_model->dataList($dis,10);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
//创建时间
$v['create_time'] = date('Y/m/d',$v['create_time']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 10:44
* @功能说明:商品详情
*/
public function goodsInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$goods_model = new ShopGoods();
$data = $goods_model->dataInfo($dis);
$farmer_model = new Farmer();
$source_model = new Source();
$cate_model = new ShopGoodsCate();
$data['farmer_title'] = $farmer_model->where(['id'=>$data['farmer_id']])->value('title');
$data['source_title'] = $source_model->where(['id'=>$data['source_id']])->value('title');
$data['cate_title'] = $cate_model->where(['id'=>$data['cate_id']])->value('title');
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 09:32
* @功能说明:添加商品
*/
public function goodsAdd(){
$input = $this->_input;
//0放入仓库 1提交审核
// $type = !empty($input['type'])?$input['type']:0;
unset($input['type']);
$input['uniacid'] = $this->_uniacid;
$input['store_id']= $this->store['id'];
$input['user_id'] = $this->getUserId();
$input['imgs'] = !empty($input['imgs'])?implode(',',$input['imgs']):'';
$core = new WxSetting($this->_uniacid);
if(!empty($input['goods_name'])){
$rest = $core->wxContentRlue($input['goods_name']);
if($rest['errcode'] != 0){
return $this->error('标题含有违法违规内容');
}
}
if(!empty($input['text'])){
$input['text'] = serialize($input['text']);
}
// if(!empty($input['text'])){
//
// $rest = $core->wxContentRlue($input['text']);
//
// if($rest['errcode'] != 0){
//
// return $this->error('标题含有违法违规内容');
// }
//
// }
$goods_model = new ShopGoods();
$id = $goods_model->dataAdd($input);
return $this->success(1);
}
/**
* @author chenniang
* @DataTime: 2022-02-25 17:49
* @功能说明:编辑商品
*/
public function goodsUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$core = new WxSetting($this->_uniacid);
if(!empty($input['goods_name'])){
$rest = $core->wxContentRlue($input['goods_name']);
if($rest['errcode'] != 0){
return $this->error('标题含有违法违规内容');
}
}
// if(!empty($input['text'])){
//
// $rest = $core->wxContentRlue($input['text']);
//
// if($rest['errcode'] != 0){
//
// return $this->error('标题含有违法违规内容');
// }
//
// }
if(!empty($input['text'])){
$input['text'] = serialize($input['text']);
}
if(isset($input['imgs'])){
$input['imgs'] = !empty($input['imgs'])?implode(',',$input['imgs']):'';
}
$goods_model = new ShopGoods();
$input['uniacid'] = $this->_uniacid;
$res = $goods_model->goodsUpdate($dis,$input);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 11:44
* @功能说明:商品上下家删除
*/
public function goodsStatusUpdate(){
$input = $this->_input;
$goods_model = new ShopGoods();
$dis = [
'id' => $input['id']
];
$res = $goods_model->dataUpdate($dis,['status'=>$input['status']]);
return $this->success($res);
}
/**
* @param $input
* @功能说明:提交审核方法
* @author chenniang
* @DataTime: 2021-03-23 14:27
*/
public function subGoodsShAction($goods_id){
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'cap_id' => $this->cap_info['id'],
'order_code' => orderCode(),
'status' => 1,
];
$goods_sh_model = new ShopGoodsSh();
$goods_sh_model->dataAdd($insert);
$id = $goods_sh_model->getLastInsID();
//提交审核
$res = $goods_sh_model->subSh($id,$goods_id);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $res;
}
/**
* @author chenniang
* @DataTime: 2021-03-23 11:31
* @功能说明:商品批量上下架
*/
public function someGoodsUpdate(){
$input = $this->_input;
$goods_model = new ShopGoods();
//全选
if(!empty($input['all'])){
$res = $goods_model->where(['store_id'=>$this->store['id'],'status'=>$input['now_status']])->where('status','>',-1)->update(['status'=>$input['status']]);
}else{
$res = $goods_model->where('id','in',$input['goods_id'])->update(['status'=>$input['status']]);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-02-28 14:08
* @功能说明:添加商品时农场主下拉框
*/
public function goodsFarmerSelect(){
$input = $this->_param;
$order_farmer = $this->model->goodsFarmerSelect($this->getUserId());
$map[] = ['id','in',$order_farmer];
$map[] = ['status','in',[2,3]];
$map[] = ['type','=',1];
$list = $this->model->where($map)->field('id,title')->select()->toArray();
return $this->success($list);
}
/**
* @author chenniang
* @DataTime: 2022-02-28 14:22
* @功能说明:添加商品时溯源下拉框
*/
public function goodsSourceSelect(){
$input = $this->_param;
$land_order_model = new LandOrder();
$source_model = new Source();
$id = $land_order_model->goodsSourceSelect($this->getUserId());
$map[] = ['id','in',$id];
$map[] = ['status','=',1];
$list = $source_model->where($map)->field('id,title')->order('id desc')->select()->toArray();
return $this->success($list);
}
/**
* @author chenniang
* @DataTime: 2022-03-01 11:03
* @功能说明:订单列表
*/
public function orderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.store_id','=',$this->store['id']];
$where = [];
if(!empty($input['name'])){
$where[] = ['b.goods_name','like','%'.$input['name'].'%'];
$where[] = ['a.order_code','like','%'.$input['name'].'%'];
}
if(!empty($input['pay_type'])){
$dis[] = ['a.pay_type','=',$input['pay_type']];
}else{
$dis[] = ['a.pay_type','>=',1];
}
$order_model = new ShopOrder();
$data = $order_model->indexDataList($dis,$where);
$arr = [
'no_pay_count' => 1,
//未发货
'no_send_count' => 2,
//已经发货
'have_send_count'=> 3
];
foreach ($arr as $ks=>$vs){
$map = [
'store_id'=> $this->store['id'],
'pay_type'=> $vs
];
$data[$ks] = $order_model->where($map)->count();
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-07 10:31
* @功能说明:分配订单给农场主
*/
public function distributionOrderFarmer(){
$input = $this->_input;
$order_model = new ShopOrder();
$dis = [
'id' => $input['id']
];
$refund_model = new ShopRefund();
//判断有无申请中的退款订单
$refund_order = $refund_model->dataInfo(['order_id'=>$input['id'],'status'=>1]);
if(!empty($refund_order)){
$this->errorMsg('该订单正在申请退款,请先处理再核销');
}
$res = $order_model->dataUpdate($dis,['farmer_show'=>1]);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-15 14:58
* @功能说明:订单详情
*/
public function orderInfo(){
$input = $this->_param;
$order_model = new ShopOrder();
$dis = [
'id' => $input['id']
];
$data = $order_model->dataInfo($dis);
$data['over_time'] -= time();
$time_arr = ['create_time','pay_time','end_time','hx_time','over_time','cancel_time'];
foreach ($time_arr as $v){
$data[$v] = !empty($data[$v])?date('Y-m-d H:i:s',$data[$v]):$data[$v];
}
$data['distance'] = distance_text($data['distance']);
//配送时间
$data['user_send_time'] = date('Y-m-d H:i',$data['send_start_time']).'~'.date('H:i',$data['send_end_time']);
$farmer_model = new Farmer();
$data['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['farmer_id']],'title');
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 17:29
* @功能说明:退款订单详情
*
*/
public function refundOrderList(){
$input = $this->_param;
$refund_model = new ShopRefund();
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.store_id','=',$this->store['id']];
$where = [];
if(!empty($input['name'])){
$where[] = ['b.goods_name','like','%'.$input['name'].'%'];
$where[] = ['a.order_code','like','%'.$input['name'].'%'];
}
if(!empty($input['status'])){
$dis[] = ['a.status','=',$input['status']];
}else{
$dis[] = ['a.status','>',-1];
}
$data = $refund_model->indexDataList($dis,$where);
$map = [
'status' => 1,
'store_id'=> $this->store['id']
];
//退款中数量
$data['ing_count'] = $refund_model->where($map)->count();
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-18 09:21
* @功能说明:拒绝退款
*/
public function noPassRefund(){
$input = $this->_input;
$refund_order_model = new ShopRefund();
$res = $refund_order_model->noPassRefund($input['id'],$this->getUserId());
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success($res);
}
/**\
* @author chenniang
* @DataTime: 2021-03-18 09:28
* @功能说明:同意退款
*/
public function passRefund(){
$input = $this->_input;
$refund_order_model = new ShopRefund();
$res = $refund_order_model->passOrder($input['id'],$input['price'],$this->payConfig(),$this->getUserId(),$input['text']);
if(!empty($res['code'])){
$this->errorMsg($res['msg']);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 17:50
* @功能说明:退款订单详情
*/
public function refundOrderInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$refund_order_model = new ShopRefund();
$data = $refund_order_model->dataInfo($dis);
$order_model = new ShopOrder();
$data['pay_order_code'] = $order_model->where(['id'=>$data['order_id']])->value('order_code');
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
$data['refund_time'] = date('Y-m-d H:i:s',$data['refund_time']);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-12-30 11:15
* @功能说明:申请提现
*/
public function applyWallet(){
$input = $this->_input;
$wallet_model = new Wallet();
$config_model = new Config();
$user = $this->user_model->dataInfo(['id'=>$this->getUserId()]);
$config = $config_model->dataInfo(['uniacid'=>$this->_uniacid]);
if($input['apply_price']>$user['wallet_cash']){
$this->errorMsg('余额不足');
}
Db::startTrans();
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'order_code' => orderCode(),
'store_id' => $this->store['id'],
'pay_price' => $input['apply_price'],
'text' => $input['text'],
'true_price' => round($input['apply_price']*$config['cash_balance']/100,2),
'balance' => $config['cash_balance'],
'type' => 2,
];
//发起提现
$res = $wallet_model->dataAdd($insert);
if($res==0){
Db::rollback();
$this->errorMsg('申请失败');
}
$water_model = new FinanceWater();
$id = $wallet_model->getLastInsID();
//添加提现记录
$res = $water_model->addWater($id,15,2,1);
if($res==0){
Db::rollback();
$this->errorMsg('申请失败');
}
$id = $water_model->getLastInsID();
//执行记录
$res = $water_model->cashArrival(0,0,$id);
if($res==0){
Db::rollback();
$this->errorMsg('申请失败');
}
Db::commit();
return $this->success($res);
}
}

View File

@@ -0,0 +1,999 @@
<?php
namespace app\farm\controller;
use app\ApiRest;
use app\farm\model\BalanceWater;
use app\farm\model\Car;
use app\farm\model\Config;
use app\farm\model\CouponRecord;
use app\farm\model\FinanceWater;
use app\farm\model\SystemInfo;
use app\farm\model\Wallet;
use app\massage\model\CarAtvRecord;
use app\farm\model\Address;
use app\farm\model\User;
use app\farm\model\Farmer;
use app\shop\model\DistributionList;
use think\App;
use think\facade\Db;
class IndexUser extends ApiRest
{
protected $model;
protected $address_model;
protected $record_model;
protected $coupon_record_model;
protected $car_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new User();
$this->address_model = new Address();
$this->record_model = new CarAtvRecord();
$this->car_model = new Car();
$this->coupon_record_model = new CouponRecord();
//积分到账
// point_success($this->_uniacid);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:48
* @功能说明:个人中心
*/
public function index(){
if(empty($this->getUserId())){
return $this->success([]);
}
$data = $this->model->dataInfo(['id'=>$this->getUserId()]);
$cap_dis[] = ['user_id','=',$this->getUserId()];
$cap_dis[] = ['type','=',1];
$cap_dis[] = ['status','in',[1,2,3,4]];
$farmer_model = new Farmer();
//查看是否是团长
$cap_info = $farmer_model->dataInfo($cap_dis);
//-1表示未申请团长1申请中2已通过3取消,4拒绝
$data['farmer_status'] = !empty($cap_info)?$cap_info['status']:-1;
$data['sh_text'] = !empty($cap_info)?$cap_info['sh_text']:'';
$where[] = ['user_id','=',$this->getUserId()];
$where[] = ['status','in',[1,2,3,4]];
$distri_model = new DistributionList();
$fx = $distri_model->dataInfo($where);
$data['fx_status'] = !empty($fx)?$fx['status']:-1;
$data['fx_text'] = !empty($fx)?$fx['sh_text']:'';
//优惠券数
// $data['coupon_count'] = $this->coupon_record_model->couponCount($this->getUserId());
$water_model = new FinanceWater();
//冻结金额
$data['frozen_cash'] = $water_model->landordFrozenCash($this->getUserId());
$data['balance_cash']= round($data['balance'] - $data['wallet_cash'],2);
$data['balance'] += $data['frozen_cash'];
$data['balance'] = round($data['balance'],2);
$info_model = new SystemInfo();
//是否含有未读消息
$data['no_read_info'] = $info_model->userHaveNews($this->getUserId(),$this->_uniacid);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:54
* @功能说明:用户地址列表
*/
public function addressList(){
$dis[] = ['user_id','=',$this->getUserId()];
$dis[] = ['status','>',-1];
$data = $this->address_model->dataList($dis,10);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:57
* @功能说明:用户地址详情
*/
public function addressInfo(){
$input = $this->_param;
$dis = [
'id' => $input['id']
];
$data = $this->address_model->dataInfo($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:58
* @功能说明:添加用户地址
*/
public function addressAdd(){
$input = $this->_input;
$input['uniacid'] = $this->_uniacid;
$input['user_id'] = $this->getUserId();
$res = $this->address_model->dataAdd($input);
if($input['status']==1){
$id = $this->address_model->getLastInsID();
$this->address_model->updateOne($id);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 15:58
* @功能说明:添加用户地址
*/
public function addressUpdate(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$res = $this->address_model->dataUpdate($dis,$input);
if(!empty($input['status'])&&$input['status']==1){
$this->address_model->updateOne($input['id']);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-07-11 22:54
* @功能说明:获取默认地址
*/
public function getDefultAddress(){
$address_model = new Address();
$address = $address_model->dataInfo(['user_id'=>$this->getUserId(),'status'=>1]);
return $this->success($address);
}
/**
* @author chenniang
* @DataTime: 2021-03-19 16:13
* @功能说明:删除地址
*/
public function addressDel(){
$input = $this->_input;
$dis = [
'id' => $input['id']
];
$res = $this->address_model->where($dis)->delete();
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-22 13:56
* @功能说明:修改用户信息 授权微信信息等
*/
public function userUpdate(){
$input = $this->_input;
$dis = [
'id' => $this->getUserId()
];
if(isset($input['coupon_atv_id'])){
unset($input['coupon_atv_id']);
}
if(isset($input['watermark'])){
unset($input['watermark']);
}
if(isset($input['openId'])){
unset($input['openId']);
}
if(isset($input['unionId'])){
unset($input['unionId']);
}
$res = $this->model->dataUpdate($dis,$input);
$user_info = $this->model->dataInfo(['id'=>$this->getUserId()]);
setCache($this->autograph, $user_info, 7200, $this->_uniacid);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-22 14:08
* @功能说明:用户信息
*/
public function userInfo(){
if(empty($this->getUserId())){
return $this->success([]);
}
$data = $this->model->dataInfo(['id'=>$this->getUserId()]);
$cap_dis[] = ['user_id','=',$this->getUserId()];
$cap_dis[] = ['type','=',1];
$cap_dis[] = ['status','in',[1,2,3,4]];
$farmer_model = new \app\farm\model\Farmer();
//查看是否是团长
$cap_info = $farmer_model->dataInfo($cap_dis);
//-1表示未申请团长1申请中2已通过3取消,4拒绝
$data['farmer_status'] = !empty($cap_info)?$cap_info['status']:-1;
$data['sh_text'] = !empty($cap_info)?$cap_info['sh_text']:'';
$data['balance_cash']= round($data['balance'] - $data['wallet_cash'],2);
$where[] = ['user_id','=',$this->getUserId()];
$where[] = ['status','in',[1,2,3,4]];
$distri_model = new DistributionList();
$fx = $distri_model->dataInfo($where);
$data['fx_status'] = !empty($fx)?$fx['status']:-1;
$data['fx_text'] = !empty($fx)?$fx['sh_text']:'';
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-03-22 13:35
* @功能说明:申请认证农场主
*/
public function applyFarmer(){
$input = $this->_input;
$farmer_model = new Farmer();
$cap_dis[] = ['user_id','=',$this->getUserId()];
$cap_dis[] = ['status','>',-1];
$cap_dis[] = ['type','=',1];
$cap_info = $farmer_model->dataInfo($cap_dis);
if(!empty($cap_info)&&in_array($cap_info['status'],[1,2,3])){
$this->errorMsg('你已经申请过农场主了,');
}
$input['uniacid'] = $this->_uniacid;
$input['user_id'] = $this->getUserId();
$input['status'] = 1;
$input['imgs'] = !empty($input['imgs'])?implode(',',$input['imgs']):'';
$input['idcard_imgs'] = !empty($input['idcard_imgs'])?implode(',',$input['idcard_imgs']):'';
if(!empty($cap_info)&&$cap_info['status']==4){
$res = $farmer_model->dataUpdate(['id'=>$cap_info['id']],$input);
}else{
$res = $farmer_model->dataAdd($input);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-09-26 10:43
* @功能说明:农场主详情
*/
public function farmerInfo(){
if(empty($this->getUserId())){
return $this->success([]);
}
$farmer_model = new Farmer();
$cap_dis[] = ['user_id','=',$this->getUserId()];
$cap_dis[] = ['status','>',-1];
$cap_dis[] = ['type','=',1];
$cap_info = $farmer_model->dataInfo($cap_dis);
return $this->success($cap_info);
}
/**
* @author chenniang
* @DataTime: 2021-07-08 11:51
* @功能说明:用户优惠券列表
*/
public function userCouponList(){
$input = $this->_param;
$this->coupon_record_model->initCoupon($this->_uniacid);
$dis = [
'user_id' => $this->getUserId(),
'status' => $input['status'],
// 'is_show' => 1
];
$data = $this->coupon_record_model->dataList($dis);
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['start_time'] = date('Y.m.d H:i',$v['start_time']).' - '.date('Y.m.d H:i',$v['end_time']);
$v['use_time'] = date('Y.m.d H:i',$v['use_time']);
}
}
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2021-07-16 22:09
* @功能说明:删除优惠券
*/
public function couponDel(){
$input = $this->_input;
$coupon = $this->coupon_record_model->dataInfo(['id'=>$input['coupon_id']]);
if($coupon['status']==1){
$this->errorMsg('待使用待卡券不能删除');
}
$res = $this->coupon_record_model->dataUpdate(['id'=>$input['coupon_id']],['is_show'=>0]);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 17:40
* @功能说明:生产二维码
*/
public function atvQr(){
$input = $this->_input;
$key = 'atv_coupon'.$input['coupon_atv_id'];
$qr = getCache($key,$this->_uniacid);
if(empty($qr)){
// $qr_insert = [
//
// 'coupon_atv_id' => $input['coupon_atv_id']
// ];
//获取二维码
$qr = $this->model->orderQr($input,$this->_uniacid);
setCache($key,$qr,86400,$this->_uniacid);
}
return $this->success($qr);
}
/**
* @author chenniang
* @DataTime: 2021-07-14 19:22
* @功能说明:授权手机号
*/
public function reportPhone ()
{
$params = $this->_input;
$encryptedData = $params[ 'encryptedData' ];
$iv = $params[ 'iv' ];
$config = longbingGetAppConfig($this->_uniacid);
$appid = $config[ 'appid' ];
// $appsecret = $config[ 'app_secret' ];
$session_key = $this->model->where(['id'=>$this->getUserId()])->value('session_key');
if(empty($session_key)){
$this->errorMsg('need login',401);
}
$data = null;
// 解密
$errCode = decryptDataLongbing( $appid, $session_key, $encryptedData, $iv, $data );
if ( $errCode == 0 )
{
$data = json_decode( $data, true );
$phone = $data[ 'purePhoneNumber' ];
}
else
{
return $this->error( $errCode );
}
$res = $this->model->dataUpdate(['id'=>$this->getUserId()],['phone'=>$phone]);
$user_info = $this->model->dataInfo(['id'=>$this->getUserId()]);
setCache($this->autograph, $user_info, 7200, $this->_uniacid);
return $this->success($phone);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:46
* @功能说明:添加到购物车
*/
public function addCar(){
$input = $this->_input;
$is_show_del = !empty($input['is_show_del'])?$input['is_show_del']:1;
if($is_show_del==1){
$this->car_model->where(['user_id'=>$this->getUserId(),'is_show'=>2])->delete();
}
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'farmer_id' => !empty($input['farmer_id'])?$input['farmer_id']:0,
'goods_id'=> $input['goods_id'],
'spe_id' => !empty($input['spe_id'])?$input['spe_id']:0,
'type' => $input['type'],
'is_show' => !empty($input['is_show'])?$input['is_show']:1,
];
$info = $this->car_model->dataInfo($insert);
//增加数量
if(!empty($info)){
$res = $this->car_model->dataUpdate(['id'=>$info['id']],['goods_num'=>$info['goods_num']+$input['goods_num']]);
$id = $info['id'];
}else{
//添加到购物车
$insert['goods_num'] = $input['goods_num'];
$insert['status'] = 1;
$res = $this->car_model->dataAdd($insert);
$id = $this->car_model->getLastInsID();
}
return $this->success($id);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:54
* @功能说明:删除购物车
*/
public function delCar(){
$input = $this->_input;
$info = $this->car_model->dataInfo(['id'=>$input['id']]);
//加少数量
if($info['goods_num']>$input['goods_num']){
$res = $this->car_model->dataUpdate(['id'=>$info['id']],['goods_num'=>$info['goods_num']-$input['goods_num']]);
}else{
$res = $this->car_model->where(['id'=>$info['id']])->delete();
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-25 10:39
* @功能说明:
*/
public function carUpdate(){
$input = $this->_input;
$res = $this->car_model->where('id','in',$input['id'])->update(['status'=>$input['status']]);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-24 14:59
* @功能说明:批量删除购物车
*/
public function delSomeCar(){
$input = $this->_input;
$dis = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'type' => $input['type']
];
$where = [];
if(!empty($input['id'])){
$where[] = ['id','in',$input['id']];
}
$res = $this->car_model->where($dis)->where($where)->delete();
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-02-10 11:28
* @功能说明:用户消费流水记录
*/
public function userConsumeWater(){
$input = $this->_param;
$dis[] = ['user_id','=',$this->getUserId()];
if(isset($input['add'])){
$dis[] = ['add','=',$input['add']];
}
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$water_model = new BalanceWater();
$data = $water_model->indexList($dis);
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-07-21 17:08
* @功能说明:申请分销商
*/
public function applyReseller(){
$input = $this->_input;
$distribution_model = new DistributionList();
$dis[] = ['status','>',-1];
$dis[] = ['user_id','=',$this->getUserId()];
$find = $distribution_model->dataInfo($dis);
if(!empty($find)&&in_array($find['status'],[1,2,3])){
$this->errorMsg('你已经申请');
}
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'user_name'=> $input['user_name'],
'mobile' => $input['mobile'],
'status' => 1,
];
if(!empty($find)&&$find['status']==4){
$res = $distribution_model->dataUpdate(['id'=>$find['id']],$insert);
}else{
$res = $distribution_model->dataAdd($insert);
}
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-08-26 14:07
* @功能说明:绑定分销商
*/
public function bindReseller(){
$input = $this->_input;
$dis = [
'fx_code' => $input['fx_code'],
'uniacid' => $this->_uniacid
];
$data = $this->model->dataInfo($dis);
if(empty($data)){
$this->errorMsg('邀请码无效');
}
if(!empty($this->getUserInfo()['pid'])){
$this->errorMsg('你已经绑定分销商');
}
$update = [
'pid' => $data['id']
];
$res = $this->model->dataUpdate(['id'=>$this->getUserId()],$update);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2021-03-23 09:39
* @功能说明:分销商详情
*/
public function resellerInfo(){
$cap_dis[] = ['user_id','=',$this->getUserId()];
$cap_dis[] = ['status','in',[1,2,3,4]];
$distribution_model = new DistributionList();
$cap_info = $distribution_model->dataInfo($cap_dis);
return $this->success($cap_info);
}
/**
* @author chenniang
* @DataTime: 2022-08-23 11:38
* @功能说明:获取app下载地址
*/
public function getAppDownloadQr(){
$data = getCode($this->_uniacid,'www.baidu.com');
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-03-14 11:55
* @功能说明:发送验证码
*/
public function sendShortMsg(){
$input = $this->_input;
//验证码验证
$config = new Config();
$dis = [
'uniacid' =>$this->_uniacid,
'phone' => $input['phone']
];
$find = $this->model->dataInfo($dis);
if(!empty($find)){
$this->errorMsg('该手机号已经被绑定');
}
$res = $config->sendSms($input['phone'],$this->_uniacid);
if(!empty($res['Message'])&&$res['Message']=='OK'){
return $this->success(1);
}else{
return $this->error($res['Message']);
}
}
/**
* @author chenniang
* @DataTime: 2022-08-26 10:29
* @功能说明:判断用户手机号
*/
public function bindUserPhone(){
$input = $this->_input;
$dis = [
'uniacid' =>$this->_uniacid,
'phone' => $input['phone']
];
$find = $this->model->dataInfo($dis);
if(!empty($find)){
$this->errorMsg('该手机号已经被绑定');
}
$short_code = getCache($input['phone'],$this->_uniacid);
//验证码验证手机号
if($input['short_code']!=$short_code){
return $this->error('验证码错误');
}
$res = $this->model->dataUpdate(['id'=>$this->getUserId()],$dis);
$user = $this->getUserInfo();
$user['phone'] = $input['phone'];
$key = 'longbing_user_autograph_' . $user['id'];
$key = md5($key);
setCache($key, $user, 7200, $this->_uniacid);
return $this->success($res);
}
/**
* @author chenniang
* @DataTime: 2022-08-26 15:45
* @功能说明:通过分销码查找分销商
*/
public function fxcodeUser(){
$input = $this->_param;
$dis = [
'is_fx' => 1,
'fx_code' => $input['fx_code'],
'uniacid' => $this->_uniacid
];
$data = $this->model->dataInfo($dis);
if(!empty($data)){
$fx_model = new DistributionList();
$data['fx_name'] = $fx_model->where(['user_id'=>$data['id'],'status'=>2])->value('user_name');
}
return $this->success($data);
}
}

596
app/farm/info/AdminMenu.php Normal file
View File

@@ -0,0 +1,596 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:29
*/
$tmp = sassAuth()==1?',{
"name": "PurchaseList",
"url": "/malls/purchase"
}':'';
$malls = <<<MALLS
{
"path": "/malls",
"component": "Layout",
"redirect": "/malls/list",
"meta": {
"menuName": "Malls",
"icon": "icon-gouwudai",
"subNavName": [{
"name": "MallsManage",
"url": [{
"name": "GoodsList",
"url": "/malls/list"
}, {
"name": "GoodsClassify",
"url": "/malls/classify"
}, {
"name": "ParameterManagement",
"url": "/malls/parameter"
} $tmp
]
}, {
"name": "StoreManage",
"url": [{
"name": "StoreList",
"url": "/malls/storeManage"
}]
}, {
"name": "OrderManage",
"url": [{
"name": "OrderManage",
"url": "/malls/orderManage"
}, {
"name": "RefundManage",
"url": "/malls/refundManage"
}]
}, {
"name": "MarketingManage",
"url": [{
"name": "AssembleList",
"url": "/malls/assemble"
}, {
"name": "RedPackit",
"url": "/malls/redPackit"
}]
}, {
"name": "MallsSet",
"url": [{
"name": "DealSet",
"url": "/malls/dealSet"
}, {
"name": "VirtualPaymentSet",
"url": "/malls/virtualPayment"
}, {
"name": "StaffChoiceGoods",
"url": "/malls/staffGoods"
}, {
"name": "MallsBanner",
"url": "/malls/banner"
}]
}, {
"name": "Distributioninfo",
"url": [{
"name": "ProfitInfo",
"url": "/malls/profit"
}, {
"name": "CommissionInfo",
"url": "/malls/commission"
}, {
"name": "TakeCashInfo",
"url": "/malls/cash"
}, {
"name": "DistributionRelation",
"url": "/malls/relation"
}, {
"name": "DistributionSetting",
"url": "/malls/disSet"
}, {
"name": "DistributionCash",
"url": "/malls/disCash"
}, {
"name": "DistributionAudit",
"url": "/malls/disaudit"
}]
}]
},
"children": [{
"path": "list",
"name": "GoodsList",
"component": "/malls/goods/list",
"meta": {
"keepAlive": true,
"refresh": false,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "GoodsList",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "edit",
"name": "GoodsEdit",
"component": "/malls/goods/edit",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "GoodsEdit",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "classify",
"name": "GoodsClassify",
"component": "/malls/goods/classify",
"meta": {
"keepAlive": true,
"refresh": false,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "GoodsClassify",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "addClassify",
"name": "SpecsClassify",
"component": "/malls/goods/addClassify",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "AddClassify",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "parameter",
"name": "ParameterManagement",
"component": "/malls/goods/parameter",
"meta": {
"keepAlive": true,
"refresh": false,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "ParameterManagement",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "parimary",
"name": "parimar",
"component": "/malls/goods/parimary",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "parimar",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "secndparimary",
"name": "secndParimar",
"component": "/malls/goods/secndparimary",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "secndParimar",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "purchase",
"name": "PurchaseList",
"component": "/malls/goods/purchase",
"meta": {
"keepAlive": true,
"refresh": false,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "PurchaseList",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "editPurchase",
"name": "PurchaseAdd",
"component": "/malls/goods/editPurchase",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "PurchaseAdd",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
},
{
"path": "wholesale",
"name": "WholesaleList",
"component": "/malls/goods/wholesale",
"meta": {
"keepAlive": true,
"refresh": false,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "WholesaleList",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "editWholesale",
"name": "WholesaleAdd",
"component": "/malls/goods/editWholesale",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "WholesaleAdd",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}
,{
"path": "storeManage",
"name": "StoreList",
"component": "/malls/store/list",
"meta": {
"keepAlive": true,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "StoreList",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "store",
"name": "StoreAdd",
"component": "/malls/store/edit",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "StoreAdd",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "orderManage",
"name": "OrderManage",
"component": "/malls/order/manage",
"meta": {
"keepAlive": true,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "OrderManage",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "orderDetail",
"name": "OrderDetail",
"component": "/malls/order/detail",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "OrderDetail",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "refundManage",
"name": "RefundManage",
"component": "/malls/order/refund",
"meta": {
"keepAlive": true,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "RefundManage",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "newAssemble",
"name": "NewAssemble",
"component": "/malls/marketing/newAssemble",
"meta": {
"keepAlive": true,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "NewAssemble",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "assemble",
"name": "AssembleList",
"component": "/malls/marketing/assemble",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "AssembleList",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "assembleManage",
"name": "AssembleManage",
"component": "/malls/marketing/assembleManage",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "AssembleManage",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "redPackit",
"name": "RedPackit",
"component": "/malls/marketing/redPackit",
"meta": {
"keepAlive": true,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "RedPackit",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "addRedPackit",
"name": "EditRedPackit",
"component": "/malls/marketing/addRedPackit",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "EditRedPackit",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "dealSet",
"name": "DealSet",
"component": "/malls/set/deal",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "DealSet",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "virtualPayment",
"name": "VirtualPaymentSet",
"component": "/malls/set/payment",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "VirtualPaymentSet",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "banner",
"name": "MallsBanner",
"component": "/malls/set/banner",
"meta": {
"keepAlive": true,
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "MallsBanner",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "editBanner",
"name": "EditBanner",
"component": "/malls/set/editBanner",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "EditBanner",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "staffGoods",
"name": "StaffChoiceGoods",
"component": "/malls/set/staffGoods",
"meta": {
"title": "MallsManage",
"isOnly": false,
"auth": [],
"pagePermission": [{
"title": "StaffChoiceGoods",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "profit",
"component": "/malls/distribution/profit",
"name": "ProfitInfo",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"keepAlive": true,
"pagePermission": [{
"title": "ProfitInfo",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "commission",
"component": "/malls/distribution/commission",
"name": "CommissionInfo",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"keepAlive": true,
"pagePermission": [{
"title": "CommissionInfo",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "cash",
"component": "/malls/distribution/takeCash",
"name": "TakeCashInfo",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"keepAlive": true,
"pagePermission": [{
"title": "TakeCashInfo",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "relation",
"component": "/malls/distribution/relation",
"name": "DistributionRelation",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"keepAlive": true,
"pagePermission": [{
"title": "DistributionRelation",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "disSet",
"component": "/malls/distribution/set",
"name": "DistributionSetting",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"pagePermission": [{
"title": "DistributionSetting",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "disCash",
"component": "/malls/distribution/cash",
"name": "DistributionCash",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"pagePermission": [{
"title": "DistributionCash",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}, {
"path": "disaudit",
"component": "/malls/distribution/audit",
"name": "DistributionAudit",
"meta": {
"title": "MallsManage",
"auth": [],
"isOnly": false,
"pagePermission": [{
"title": "DistributionAudit",
"index": 0,
"auth": ["view", "add", "edit", "del", "outport"]
}]
}
}]
}
MALLS;
//return json_decode($menu, true) ;
return ["shop" => $malls];

View File

@@ -0,0 +1,51 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:29
*/
$goods = <<<GOODS
{
"title":"商品列表",
"type":"goodsList",
"icon":"iconGoodsList",
"isDelete":true,
"addNumber":1,
"attr":[
],
"data":{
"title":"商品列表",
"isShowPush":false,
"limit":""
},
"dataList":[
]
}
GOODS;
$search = <<<SEARCH
{"title":"搜索栏","type":"search","iconPath":"iconsousuo","isDelete":true,"addNumber":1,"attr":[{"title":"是否显示分类","type":"Switch","name":"isShowCateAll"}],"data":{"placeholder":"请输入搜索内容","isShowCateAll":true}}
SEARCH;
//模块组件 后台DIY页面的左侧
return [
[
"title" => "业务组件",
'type' => 'shopCompoent',
'data' =>[
json_decode($search, true),
json_decode($goods, true),
]
],
];

View File

@@ -0,0 +1,276 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:29
*/
$defaultPage=<<<DEFAULT
{
"key": 2,
"list": [{
"title": "搜索栏",
"type": "search",
"iconPath": "iconsousuo",
"isDelete": true,
"addNumber": 1,
"attr": [{
"title": "是否显示全部分类",
"type": "Switch",
"name": "isShowCateAll"
}],
"data": {
"placeholder": "请输入搜索内容",
"isShowCateAll": true
}
},
{
"title": "轮播图",
"type": "banner",
"icon": "iconlunbo",
"isDelete": true,
"addNumber": 9999,
"attr": [{
"title": "选择模板",
"type": "ChooseModule",
"name": "bannerName",
"data": [{
"title": "通屏轮播",
"name": "banner-tongping",
"img": "http://longbingcdn.xiaochengxucms.com/admin/diy/banner-tongping.png"
}]
},
{
"title": "图片列表",
"type": "ImageLink",
"name": "bannerList",
"isDraggable": true,
"isDelete": true,
"data": [{
"title": "图片",
"type": "UploadImage",
"name": "img",
"desc": "750*350"
},
{
"title": "链接类型",
"type": "Select",
"name": "linkType",
"data": [{
"label": "小程序内部页面",
"value": 4
},
{
"label": "其他小程序",
"value": 2
},
{
"label": "跳转网页",
"value": 3
},
{
"label": "拨打电话",
"value": 1
}
]
},
{
"title": "链接地址",
"type": "Tag",
"name": "link"
}
]
},
{
"title": "添加模板",
"type": "Add",
"name": "addMouduleName",
"addNumber": 10,
"data": [{
"link": [{
"title": ""
}],
"linkType": 4,
"img": [{
"url": "http://longbingcdn.xiaochengxucms.com/admin/diy/default.png"
}]
}]
}
],
"data": {
"style": {
"height": 350,
"whiteSpace": 0,
"wingBlank": 0
},
"bannerName": "banner-tongping",
"addMouduleName": "bannerList",
"bannerList": []
},
"id": 1591856492396,
"compontents": "base"
},
{
"title": "导航",
"type": "column",
"icon": "icondaohang1",
"isDelete": true,
"addNumber": 9999,
"attr": [{
"title": "多少行",
"type": "InputNumber",
"name": "row"
},
{
"title": "每行多少列",
"type": "InputNumber",
"name": "col"
},
{
"title": "图片列表",
"type": "ImageLink",
"name": "columnList",
"isDraggable": true,
"isDelete": true,
"data": [{
"title": "按钮文字",
"type": "Input",
"name": "title"
},
{
"title": "图片",
"type": "UploadImage",
"name": "img",
"desc": "100*100"
},
{
"title": "链接类型",
"type": "Select",
"name": "linkType",
"data": [{
"label": "小程序内部页面",
"value": 4
},
{
"label": "其他小程序",
"value": 2
},
{
"label": "跳转网页",
"value": 3
},
{
"label": "拨打电话",
"value": 1
}
]
},
{
"title": "链接地址",
"type": "Tag",
"name": "link"
}
]
},
{
"title": "添加模板",
"type": "Add",
"name": "addMouduleName",
"addNumber": 16,
"data": [{
"link": [{
"title": ""
}],
"linkType": 4,
"img": [{
"url": "http://longbingcdn.xiaochengxucms.com/admin/diy/default.png"
}]
}]
}
],
"data": {
"row": {
"number": 2,
"min": 1,
"max": 2
},
"col": {
"number": 4,
"min": 4,
"max": 5
},
"style": {
"fontColor": "#666",
"background": "#ffffff",
"whiteSpace": 30,
"wingBlank": 0
},
"addMouduleName": "columnList",
"columnList": []
},
"id": 1591856495749,
"compontents": "base"
},
{
"title": "卡券",
"type": "couponList",
"icon": "iconCouponList",
"isDelete": true,
"addNumber": 1,
"attr": [{
"title": "模板名称",
"type": "Input",
"name": "title",
"maxLength": 10
},
{
"title": "卡券样式",
"type": "Radio",
"name": "type",
"data": [{
"label": 1,
"title": "弹窗样式"
},
{
"label": 2,
"title": "列表样式"
}
]
}
],
"data": {
"title": "领取卡券",
"type": 2,
"dataList": []
},
"id": 1591856498485,
"compontents": "operate"
},
{
"title": "商品列表",
"type": "goodsList",
"icon": "iconGoodsList",
"isDelete": true,
"addNumber": 1,
"attr": [],
"data": {
"title": "商品列表",
"limit": "",
"dataList": []
},
"id": 1591856499273,
"compontents": "shopCompoent"
}
]
}
DEFAULT;
$pages = json_decode( $defaultPage , true);
return $pages;

46
app/farm/info/DiyLink.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:29
*/
//模块组件 后台DIY页面的左侧
return [
//链接类型
[
'key' => 2,
"title" => "商城",
"type" => "shop",
"data" => [
[
//接口请求路径 api_path 不为空, 返回 page + '?' 数据参数
"api_path" => "/diy/admin/Module/functionPage",
//已经取消了
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "功能页面",
//小程序路径
"page" => "common_page"
],[
//接口请求路径 api_path 不为空, 返回 page + '?' 数据参数
"api_path" => "/shop/admin/AdminShopType/cateInfoPage",
//已经取消了
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商品分类页面",
//小程序路径
"page" => "/shop/pages/filter"
],[
//接口请求路径 api_path 不为空, 返回 page + '?' 数据参数
"api_path" => "/shop/admin/AdminShopGoods/goodsInfoPage",
//已经取消了
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商品详情页面",
//小程序路径
"page" => "/pages/shop/detail"
],
]
],
];

View File

@@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:29
*/
//底部菜单自定义
return [
[
//底部菜单编号
'key' => 2 ,
//是否显示
'is_show' => 1 ,
//图标
'iconPath' => 'icon-shangcheng1',
//选中图标样式
'selectedIconPath' => 'icon-shangcheng',
//那个页面 英文名称
'pageComponents' => 'shopHome',
//名称
'name' => '商城',
'url' => '',
'url_jump_way' => '0',
'url_out' => '',
'is_delete' => false ,
'bind_compoents'=>[
'base',
'shopCompoent',
'operate'
],
'bind_links' => [
'shop'
],
'page'=> []
],
];

View File

@@ -0,0 +1,86 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:29
*/
//模块组件 后台DIY页面的左侧
$tmp = [
//链接类型
[
'id'=>'',
'level'=>1,
'key'=> 2,
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商城页面",
//小程序路径
"path" => "/pages/user/home?key=2&staff_id="
],[
'id'=>'',
'level'=>2,
'key'=> 2,
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商城购物车",
//小程序路径
"path" => "/shop/pages/cart"
],[
'id'=>'',
'level'=>2,
'key'=> 2,
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商城卡券列表",
//小程序路径
"path" => "/shop/pages/coupon/receive?staff_id="
],
[
'id'=>'',
'level'=>2,
'key'=> 2,
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商城全部分类",
//小程序路径
"path" => "/shop/pages/cate"
],
[
'id'=>'',
'level'=>2,
'key'=> 2,
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商城采购模版",
//小程序路径
"path" => "/shop/pages/purchase/list?staff_id="
],
[
'id'=>'',
'level'=>2,
'key'=> 2,
//"params"=>"{"page" : "PAGE", "page_count" : "PAGE_COUNT"}",
"title" => "商城砍价列表页",
//小程序路径
"path" => "/shop/pages/bargain/list?staff_id="
],
];
return $tmp;

32
app/farm/info/Info.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: shuixian
* Date: 2019/11/20
* Time: 18:30
*/
return [
//模块名称[必填]
'name' => 'farm',
//模块标题[必填]
'title' =>'智慧农业',
//内容简介
'desc' =>'',
//封面图标
'icon' =>'',
//模块类型[必填] model:模块 可以出现在左侧一级 app:应用中心 , 是一个应用中心的应用
'type' => 'model',
// 模块唯一标识[必填],格式:模块名.开发者标识.module
'identifier' => 'farm.longbing.module',
// 版本[必填],格式采用三段式:主版本号.次版本号.修订版本号
'version' => '1.0.80',
// 模块依赖[可选],格式[[模块名, 模块唯一标识, 依赖版本, 对比方式]]
'need_module'=> [],
// 应用依赖[可选],格式[[插件名, 应用唯一标识, 依赖版本, 对比方式]]
'need_app' => [],
//订阅消息
'tmpl_name'=>['pay_order','send_order','land_order','land_over']
];

View File

@@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace app\farm\info;
use longbingcore\permissions\PermissionAbstract;
/**
* 商城模块功能权限
* Class PermissionAppstore
*/
class PermissionFarm extends PermissionAbstract {
const tabbarKey = null;
//后台管理菜单对应key[必填] , 当前模块文件夹名称
const adminMenuKey = 'farm';
public $saasKey ;
const apiPaths = [];
public function __construct(int $uniacid,$infoConfigOptions = [])
{
$this->saasKey = longbing_get_auth_prefix('AUTH_SHOP') ;
parent::__construct($uniacid, self::tabbarKey, self::adminMenuKey, $this->saasKey, self::apiPaths , $infoConfigOptions);
}
/**
* 返回saas端授权结果
* @return bool
*/
public function sAuth(): bool
{
return true ;
}
/**
* 返回p端授权结果
* @return bool
*/
public function pAuth(): bool
{
return false;
//代理管理端可以控制商城是否展示权限 , 这里需要判断权限
$pAuthConfig = $this->getPAuthConfig();
//必须平台授权才能使用
//dump($this->getAuthIsPlatformCheck());exit;
if($this->getAuthIsPlatformCheck()){
//根据授权而定
if ($pAuthConfig ){
// dump($pAuthConfig);exit;
return $pAuthConfig['shop_switch'] ? true : false ;
}
}
return true;
}
/**
* 返回c端授权结果
*
* @param int $user_id
* @return bool
* @author ArtizanZhang
* @DataTime: 2019/12/9 17:13
*/
public function cAuth(int $user_id): bool
{
return true;
}
/**
* 添加商品数量
*
* @author shuixian
* @DataTime: 2019/12/19 19:02
*/
public function getAddGoodsNumber(){
return $this->getAuthVaule( longbing_get_auth_prefix('AUTH_GOODS') , 4);
}
}

View File

@@ -0,0 +1,204 @@
<?php
$radar_msg = [
[
"sign"=> "copy",
"type"=> 8,
"max"=> 0,
"pid"=> 0,
"msg"=> "请及时留意雷达动态",
"operation"=> "咨询",
"item"=> "产品",
"show_count"=> 1,
"table_name"=> "",
"field"=> "",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 1,
"max"=> 0,
"pid"=> 0,
"msg"=> "请尽快把握商机",
"operation"=> "浏览",
"item"=> "商城列表",
"show_count"=> 1,
"table_name"=> "longbing_card_shop_type",
"field"=> "title",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 2,
"max"=> 0,
"pid"=> 0,
"msg"=> "请尽快把握商机,主动提供细致的商品讲解将大大有利于成交",
"operation"=> "正在查看",
"item"=> "商品",
"show_count"=> 0,
"table_name"=> "longbing_card_goods",
"field"=> "name",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 11,
"max"=> 0,
"pid"=> 0,
"msg"=> "请尽快把握商机",
"operation"=> "浏览",
"item"=> "商品分类列表",
"show_count"=> 1,
"table_name"=> "longbing_card_shop_type",
"field"=> "title",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 19,
"max"=> 0,
"pid"=> 0,
"msg"=> "请前往订单中心查看详情",
"operation"=> "订单商品已发货,系统订单号为:",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 20,
"max"=> 0,
"pid"=> 0,
"msg"=> "请前往订单中心查看详情",
"operation"=> "自提商品已提货",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 21,
"max"=> 0,
"pid"=> 0,
"msg"=> "请等待管理员审核并注意查收",
"operation"=> "已申请退款",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 22,
"max"=> 0,
"pid"=> 0,
"msg"=> "请前往订单中心查看详情",
"operation"=> "已取消申请退款",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 23,
"max"=> 0,
"pid"=> 0,
"msg"=> "请前往订单中心查看详情",
"operation"=> "管理员拒绝退款",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "view",
"type"=> 24,
"max"=> 0,
"pid"=> 0,
"msg"=> "请注意查收",
"operation"=> "退款成功",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 1,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "order",
"type"=> 1,
"max"=> 0,
"pid"=> 0,
"msg"=> "请在订单中心查看详情",
"operation"=> "已购买商品",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 2,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "order",
"type"=> 2,
"max"=> 0,
"pid"=> 0,
"msg"=> "请在订单中心查看详情",
"operation"=> "已参与拼团",
"item"=> "",
"show_count"=> 0,
"table_name"=> "longbing_card_shop_order",
"field"=> "out_trade_no",
"send"=> 2,
"uniacid"=> 2,
"status"=> 1
],
[
"sign"=> "order",
"type"=> 3,
"max"=> 0,
"pid"=> 0,
"msg"=> "请在预约订单中心查看详情",
"operation"=> "预约了",
"item"=> "服务",
"show_count"=> 0,
"table_name"=> "lb_appoint_record",
"field"=> "name,phone,project_id,start_time,remark",
"send"=> 2,
"uniacid"=> 2,
"status"=> 1
],
];
return $radar_msg;

455
app/farm/info/Subscribe.php Normal file
View File

@@ -0,0 +1,455 @@
<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace app\shop\info;
use app\bargain\info\PermissionBargain;
use app\card\model\CardExtension;
use app\radar\model\RadarOrder;
use app\shop\model\IndexShopCollage;
use longbingcore\diy\BaseSubscribe;
/**
* @author shuixian
* @DataTime: 2019/12/11 16:23
* Class Subscribe
* @package app\ucenter\info
*/
class Subscribe extends BaseSubscribe
{
/**
* 相应个人中心工具菜单
*
* @return mixed
* @author shuixian
* @DataTime: 2019/12/12 11:24
*/
public function onAddWorkCenterModelMenu()
{
$permissson = new PermissionShop($this->_uniacid);
if($permissson->pAuth()) {
$modelMenu = [
"title" => '商品服务',
"desc" => '',
"show" => true,
"row" => 4,
"list" => [
[
"title" => "我的收入",
"icon" => "icontixianguanli",
"link" => "/shop/pages/partner/income",
"linkType" => 4
],
[
"title" => "订单管理",
"icon" => "iconwodedingdan",
"link" => "/shop/pages/order/list?target=staff",
"linkType" => 4
],
[
"title" => "退款管理",
"icon" => "iconwodeshouhou",
"link" => "/shop/pages/refund/list?target=staff",
"linkType" => 4
],
[
"title" => "推荐商品",
"icon" => "icontuijianshangpin",
"link" => "/shop/pages/staff/goods/push",
"linkType" => 4
],
[
"title" => "卡券管理",
"icon" => "iconwodekaquan",
"link" => "/shop/pages/staff/coupon/list",
"linkType" => 4
]
]
];
return [$modelMenu];
}
return [];
}
/**
* 名片展示页获取其他模块数据
*
* @param $params
* @return array
* @author shuixian
* @DataTime: 2019/12/24 14:24
*/
public function onCardInfo($params)
{
//获取推荐商品 By.jingshuixian
$modelExtension = new CardExtension();
$goods_list = $modelExtension->cardExtensionList($params['staff_id'], $this->_uniacid);
$collage_model = new IndexShopCollage();
foreach ($goods_list as $key => $val) {
$goods_list[$key]['is_collage'] = 0;
$count = $collage_model->getCollage(['goods_id' => $val['id'], 'uniacid' => $this->_uniacid, 'status' => 1]);
if (!empty($count)) $goods_list[$key]['is_collage'] = 1;
}
return ['goods_list'=>$goods_list];
}
/**
* 客户获取列表查询
*
* @param $data
* @return array
* @author shuixian
* @DataTime: 2019/12/26 10:30
*/
public function onStaffCustomerList($data)
{
// 商城订单
$orderCount = RadarOrder::where( [ [ 'pay_status', '=', 1 ],
[ 'order_status', '<>', 1 ],
[ 'user_id', '=', $data[ 'uid' ] ],
[ 'to_uid', '=', $data[ 'to_uid' ]],
[ 'refund_status', '=', 0 ] ]
)
->count();
$returnData[ 'count' ] = $orderCount;
$returnData[ 'title' ] = "订单";
return [$returnData];
}
/**
* @param $data
* @功能说明:处理一下数据 主要是权限方面的
* @author chenniang
* @DataTime: 2020-12-16 16:21
*/
public function onDiyModuleMenuShop($data){
if(!empty($data['data']['list'])){
foreach ($data['data']['list'] as $v){
if($v['icon']!='icontemplate'||$data['shop_auth']==true){
$arr[] = $v;
}
}
$data['data']['list'] = $arr;
}
return $data;
}
/**
* 监听用户中心模块
*
* @return array
* @author shuixian
* @DataTime: 2019/12/18 14:04
*/
public function onAddUcenterCompoent(){
$this->getUserId();
$user = longbingGetUserInfo($this->getUserId() , $this->_uniacid);
$last_staff_id = !empty($user['last_staff_id'])?$user['last_staff_id']:0;
$moduleMenuShopOrder = <<<COMPOENT
{
"title": "商城订单",
"type": "moduleMenuShopOrder",
"icon": "iconshoporder",
"isDelete": true,
"addNumber": 1,
"attr": [
{
"title": "模板名称",
"type": "Switch",
"name": "isShowTitle"
},
{
"title": "选择模板",
"type": "ChooseModule",
"name": "module",
"data": [
{
"title": "一行多列",
"name": "module-menu-row",
"img": "http://longbingcdn.xiaochengxucms.com/admin/diy/module-menu-col.jpg"
},
{
"title": "一行一列",
"name": "module-menu-col",
"img": "http://longbingcdn.xiaochengxucms.com/admin/diy/module-menu-row.jpg"
}
]
},
{
"title": "一行多少列",
"type": "InputNumber",
"name": "row"
}
],
"data": {
"isShowTitle": false,
"module": "module-menu-row",
"row": {
"number": 4,
"min": 2,
"max": 5,
"label": "请输入"
},
"list": [
{
"title": "全部",
"icon": "iconwodedingdan",
"link": {
"type": 2,
"url": "/shop/pages/order/list?index=0"
}
},
{
"title": "待付款",
"icon": "icondingdandaifukuan",
"link": {
"type": 2,
"url": "/shop/pages/order/list?index=1"
}
},
{
"title": "待发货",
"icon": "icondingdandaifahuo",
"link": {
"type": 2,
"url": "/shop/pages/order/list?index=2"
}
},
{
"title": "待收货",
"icon": "icondingdandaishouhuo",
"link": {
"type": 2,
"url": "/shop/pages/order/list?index=3"
}
},
{
"title": "已完成",
"icon": "icondingdanyiwancheng",
"link": {
"type": 2,
"url": "/shop/pages/order/list?index=4"
}
}
]
}
}
COMPOENT;
$tmp = sassAuth()==1?',
{
"title": "我的采购模板",
"icon": "icontemplate",
"link": {
"type": 2,
"url": "/shop/pages/purchase/list?staff_id='.$last_staff_id.'"'.'
}
}':'';
$bargain_p = new PermissionBargain($this->_uniacid);
$bargain_auth = $bargain_p->pAuth();
$bargain = $bargain_auth==true?',
{
"title": "我的砍价",
"icon": "iconkanjiajilu",
"link": {
"type": 2,
"url": "/shop/pages/bargain/record"
}
}':'';
$moduleMenuShop = <<<COMPOENT
{
"title": "商城工具",
"type": "moduleMenuShop",
"icon": "iconshop",
"isDelete": true,
"addNumber": 1,
"attr": [
{
"title": "模板名称",
"type": "Switch",
"name": "isShowTitle"
},
{
"title": "选择模板",
"type": "ChooseModule",
"name": "module",
"data": [
{
"title": "一行多列",
"name": "module-menu-row",
"img": "http://longbingcdn.xiaochengxucms.com/admin/diy/module-menu-col.jpg"
},
{
"title": "一行一列",
"name": "module-menu-col",
"img": "http://longbingcdn.xiaochengxucms.com/admin/diy/module-menu-row.jpg"
}
]
},
{
"title": "一行多少列",
"type": "InputNumber",
"name": "row"
}
],
"data": {
"isShowTitle": false,
"module": "module-menu-row",
"row": {
"number": 4,
"min": 2,
"max": 5,
"label": "请输入"
},
"list": [
{
"title": "我的售后",
"icon": "iconwodeshouhou",
"link": {
"type": 2,
"url": "/shop/pages/refund/list"
}
},
{
"title": "我的收入",
"icon": "icontixianguanli",
"link": {
"type": 2,
"url": "/shop/pages/partner/income"
}
},
{
"title": "我的卡券",
"icon": "iconwodekaquan",
"link": {
"type": 2,
"url": "/shop/pages/coupon/list"
}
},
{
"title": "分销商品",
"icon": "iconquanmianfenxiao",
"link": {
"type": 2,
"needStaffId": true,
"url": "/shop/pages/partner/distribution?staff_id=$last_staff_id"
}
},
{
"title": "我的地址",
"icon": "icondizhi2",
"link": {
"type": 2,
"url": "/shop/pages/address/list"
}
}$bargain
$tmp
]
}
}
COMPOENT;
$permission = new PermissionShop($this->_uniacid);
$compoentList = [] ;
if($permission->pAuth()){
$compoentList = [
json_decode($moduleMenuShopOrder, true),
json_decode($moduleMenuShop, true)
] ;
}
return $compoentList ;
}
/**
* 监听代理管理端授权小程序事件
*
* @param $data
* @return array
* @author shuixian
* @DataTime: 2019/12/27 17:33
*/
public function onAgentAppAuthEdit($config){
$returnArr = [] ;
$permission = new PermissionShop(0);
$shop_switch = [] ;
if($permission->sAuth() && $permission->infoConfig['auth_platform'] ) {
$shop_switch['formType'] = 'radio';
$shop_switch['name'] = 'shop_switch';
$shop_switch['value'] = $config ? $config[ $shop_switch['name'] ] : 0;
$shop_switch['title'] = $permission->info['title'];
$returnArr[] = $shop_switch;
}
$pay_shop = [] ;
if($permission->sAuth() && $permission->infoConfig['auth_platform'] ) {
$pay_shop['formType'] = 'radio';
$pay_shop['name'] = 'pay_shop';
$pay_shop['value'] = $config ? $config[ $pay_shop['name'] ] : 0;
$pay_shop['title'] = $permission->info['title'].'支付';
$returnArr[] = $pay_shop;
}
return $returnArr ;
}
}

View File

View 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;
}
}

View 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
View 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():[];
}
}

View 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;
}
}

View 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
View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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():[];
}
}

View 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;
}
}

View 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
View 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;
}
}

View 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
View 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;
}
}

View 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;
}
}

View 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
View 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
View 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():[];
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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
View 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
View 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;
}
}

View 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
View 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
View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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
View 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;
}
}

View 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():[];
}
}

View 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
View 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("&amp;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;
}
}

View 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'].'&notice=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'].'&notice=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;
}
}

View 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;
}
}

View 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
View 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
View 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
View 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
View 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():[];
}
}

View 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
View 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;
}
}

View 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
View 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;
}
}

View 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;
}
}

View 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
View 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
View 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;
}
}

View 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;
}
}

View 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():[];
}
}

View 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&notice=1":"land/pages/order/detail?id=".$order['id']."&tab=2&notice=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;
}
}

View 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;
}
}

View 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;
}
}

View 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

File diff suppressed because it is too large Load Diff

View 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;
}
}

View 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;
}
}

View 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():[];
}
}

Some files were not shown because too many files have changed in this diff Show More