初始化代码

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,91 @@
<?php
namespace app\massage\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;
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Admin extends BaseModel
{
//定义表名
protected $name = 'shequshop_school_admin';
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page){
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Article extends BaseModel
{
//定义表名
protected $name = 'shequshop_school_article';
protected $append = [
'create_time_text'
];
public function getCreateTimeTextAttr($value,$data){
if(!empty($data['create_time'])){
return date('Y.m.d H:i',$data['create_time']);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page=10){
$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,93 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class BalanceCard extends BaseModel
{
//定义表名
protected $name = 'massage_service_balance_card';
//
// protected $append = [
//
// 'spe_list',
//
// 'all_stock',
//
// 'show_price'
//
// ];
/**
* @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,256 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\member\model\Level;
use app\member\model\Rights;
use longbingcore\wxcore\PospalApi;
use think\facade\Db;
class BalanceOrder extends BaseModel
{
//定义表名
protected $name = 'massage_service_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'],
'member_level' => $order['member_level'],
'vip_time' => $user['vip_time']==0?time():0
];
//修改用户余额
$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();
}
//给会员权益
if(!empty($order['member_level'])){
$rights_model = new Rights();
$rights_model->giveRights($order['member_level'],$order['user_id'],$order['id']);
}
Db::commit();
//向银豹同步会员
if(!empty($order['member_level'])){
$level_model = new Level();
$api_model = new PospalApi();
$level = $level_model->levelInfo(['id'=>$order['member_level']]);
$nickName = $user_model->where(['id'=>$order['user_id']])->value('nickName');
$insert = [
'categoryName' => $level['title'],
'discount' => $level['discount'],
'number' => time().rand(1,100),
'name' => !empty($nickName)?$nickName:$order['phone'],
'phone' => $order['phone'],
];
$res = $api_model->addMember($insert);
if($res['status']!='success'){
//修改订单信息
$this->dataUpdate(['id'=>$order['id']],['error_msg'=>$res['messages'][0]]);
}else{
$this->dataUpdate(['id'=>$order['id']],['have_syn'=>1]);
}
}
}
return true;
}
}

View File

@@ -0,0 +1,221 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\farm\model\BreedOrderGoods;
use app\farm\model\ClaimOrder;
use app\farm\model\LandOrder;
use think\facade\Db;
class BalanceWater extends BaseModel
{
//定义表名
protected $name = 'massage_service_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'])){
$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']])->column('goods_name');
//养殖
}elseif($data['type']==3){
$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){
$shop_order_model = new LandOrder();
$title = $shop_order_model->where(['id'=>$data['order_id']])->column('massif_title');
}
return $title;
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 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){
$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'];
}
}
return $data;
}
/**
* @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;
default:
$text = '购买储值卡1';
break;
}
return $text;
}
/**
* @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,75 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Banner extends BaseModel
{
//定义表名
protected $name = 'massage_service_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: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
}

153
app/massage/model/Car.php Normal file
View File

@@ -0,0 +1,153 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Car extends BaseModel
{
//定义表名
protected $name = 'massage_service_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('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 17:21
* @功能说明:购物车价格
*/
public function carPriceAndCount($user_id,$is_car=0){
$list = $this->carList($user_id);
$data['list'] = $this->carList($user_id,$is_car);
if(!empty($list)){
$data['car_price'] = round(array_sum(array_column($list,'all_price')),2);
$data['total_circle'] = round(array_sum(array_column($list,'total_circle')),2);
$data['car_count'] = array_sum(array_column($list,'num'));
$data['total_discount'] = 0;
$data['coupon_id'] = 0;
}else{
$data['car_price'] = 0;
$data['car_count'] = 0;
$data['total_discount'] = 0;
$data['coupon_id'] = 0;
$data['total_circle'] = 0;
}
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-03-18 17:35
* @功能说明:购物车列表
*/
public function carList($user_id,$all=0){
$dis = [
'a.user_id' => $user_id,
'b.status' => 1,
//'c.cap_id' => $cap_id
];
if($all==0){
$dis['a.status'] = 1;
}
$data = $this->alias('a')
->join('shequshop_car_goods b','a.goods_id = b.id')
->where($dis)
->field('a.id,a.goods_id,a.status,a.uniacid,a.num,b.title,b.cover,b.price,ROUND(b.price*a.num,2) as all_price,ROUND(b.price*a.num,2) as true_price,ROUND(b.number*a.num,2) as total_circle,b.number as circle ')
->group('a.id')
->select()
->toArray();
return $data;
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarAtvContent extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_atv_content';
/**
* @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,$mapor=[]){
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
// $data = $this->alias('a')
// ->join('massage_service_user_list b','a.user_id = b.id')
// ->where($dis)
// ->where(function ($query) use ($mapor){
// $query->whereOr($mapor);
// })
// ->field('a.*,b.nickName')
// ->group('a.id')
// ->order('a.id desc')
// ->paginate($page)
// ->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
}

View File

@@ -0,0 +1,217 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarAtvList extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_atv_list';
protected $append = [
'content'
];
/**
* @author chenniang
* @DataTime: 2021-09-15 14:31
* @功能说明:获取活动内容
*/
public function getContentAttr($value,$data){
if(!empty($data['id'])){
$content = Db::name('shequshop_car_atv_content_content')->where(['atv_id'=>$data['id']])->column('content_id');
return array_values($content);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
if(isset($data['content'])){
$content = $data['content'];
unset($data['content']);
}
$res = $this->insert($data);
if(!empty($content)){
$id = $this->getLastInsID();
$this->updateSome($id,$content,$data['uniacid']);
}
return $res;
}
/**
* @author chenniang
* @DataTime: 2021-09-23 18:06
* @功能说明:根据活动时间修改活动状态
*/
public function initAtv(){
$this->where('atv_s_time','>',time())->update(['atv_status'=>1]);
$this->where('atv_e_time','<',time())->update(['atv_status'=>3]);
$this->where('atv_s_time','<',time())->where(['atv_status'=>1])->update(['atv_status'=>2]);
return true;
}
/**
* @author chenniang
* @DataTime: 2021-09-15 11:22
* @功能说明:
*/
public function updateSome($id,$content,$uniacid){
Db::name('shequshop_car_atv_content_content')->where(['atv_id'=>$id])->delete();
if(!empty($content)){
foreach ($content as $value){
$insert = [
'uniacid' => $uniacid,
'content_id' => $value,
'atv_id' => $id
];
Db::name('shequshop_car_atv_content_content')->insert($insert);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-10-20 10:02
* @功能说明:判断报名内容是否在使用
*/
public function atvContentIng($content_id){
$dis[] = ['a.status','>',-1];
$dis[] = ['b.content_id','=',$content_id];
$data = $this->alias('a')
->join('shequshop_car_atv_content_content b','a.id = b.atv_id')
->where($dis)
->find();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
if(isset($data['content'])){
$content = $data['content'];
unset($data['content']);
}
$res = $this->where($dis)->update($data);
if(!empty($content)){
$id = $this->getLastInsID();
$this->updateSome($data['id'],$content,$data['uniacid']);
}
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page=10,$mapor=[]){
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
// $data = $this->alias('a')
// ->join('massage_service_user_list b','a.user_id = b.id')
// ->where($dis)
// ->where(function ($query) use ($mapor){
// $query->whereOr($mapor);
// })
// ->field('a.*,b.nickName')
// ->group('a.id')
// ->order('a.id desc')
// ->paginate($page)
// ->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
}

View File

@@ -0,0 +1,632 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\shop\model\RefundOrder;
use think\facade\Db;
class CarAtvRecord extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_atv_record';
protected $append = [
'content',
'time_text',
'game_info',
'hx_user_name'
];
/**
* @author chenniang
* @DataTime: 2021-09-28 14:12
* @功能说明:核销人姓名
*/
public function getHxUserNameAttr($value,$data){
if(!empty($data['hx_user'])){
$user_model = new User();
$name = $user_model->where(['id'=>$data['hx_user']])->value('nickName');
return $name;
}
}
/**
* @author chenniang
* @DataTime: 2021-09-27 16:21
* @功能说明:赛事信息
*/
public function getGameInfoAttr($value,$data){
if(!empty($data['id'])){
$game_model = new CarGame();
$dis = [
'type' => 1,
'record_id' => $data['id']
];
$list = $game_model->dataInfo($dis);
if(!empty($list)){
$list['best_time'] = game_time($list['best_time']);
$list['total_time'] = game_time($list['total_time']);
}
return $list;
}
}
/**
* @param $value
* @param $data
* @功能说明:转换时间
* @author chenniang
* @DataTime: 2021-09-26 1 4:11
*/
public function getTimeTextAttr($value,$data){
if(!empty($data['start_time'])&&!empty($data['end_time'])){
$time = date('Y.m.d H:i',$data['start_time']).'-'.date('Y.m.d H:i',$data['end_time']);
return $time;
}
}
/**
* @author chenniang
* @DataTime: 2021-09-15 14:31
* @功能说明:获取活动内容
*/
public function getContentAttr($value,$data){
if(!empty($data['id'])){
$content = Db::name('shequshop_car_atv_record_content')->where(['record_id'=>$data['id']])->select()->toArray();
return array_values($content);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
if(isset($data['content'])){
$content = $data['content'];
unset($data['content']);
}
$res = $this->insert($data);
if(!empty($content)){
$id = $this->getLastInsID();
$this->updateSome($id,$content,$data['uniacid']);
}
return $res;
}
/**
* @author chenniang
* @DataTime: 2021-09-15 11:22
* @功能说明:
*/
public function updateSome($id,$content,$uniacid){
Db::name('shequshop_car_atv_record_content')->where(['record_id'=>$id])->delete();
if(!empty($content)){
foreach ($content as $value){
$insert = [
'uniacid' => $uniacid,
'content_id' => $value['content_id'],
'content_key' => $value['content_key'],
'content_value' => $value['content_value'],
'content_type' => $value['content_type'],
'record_id' => $id
];
Db::name('shequshop_car_atv_record_content')->insert($insert);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
if(isset($data['content'])){
$content = $data['content'];
unset($data['content']);
}
$res = $this->where($dis)->update($data);
if(!empty($content)){
$id = $this->getLastInsID();
$this->updateSome($data['id'],$content,$data['uniacid']);
}
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page=10,$mapor=[]){
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:成绩排行版
*/
public function topRecordList($dis,$page=10,$mapor=[]){
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->where($dis)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.nickName,b.avatarUrl')
->group('a.id')
->order('a.result asc,a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:成绩排行版(可根据时间)
*/
public function timeTopRecordList($dis,$page=10,$time = 1,$mapor=[]){
switch ($time){
case 1:
$time_text = 'day';
break;
case 2:
$time_text = 'week';
break;
case 3:
$time_text = 'month';
break;
case 4:
$time_text = 'year';
break;
}
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->join('shequshop_car_game c','a.id = c.record_id')
->where($dis)
->whereTime('a.start_time',$time_text)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.nickName')
->group('a.id')
->order('c.best_time asc,a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:积分排行榜
*/
public function integralRecordList($dis,$page=10,$mapor=[]){
// $data = $this->alias('a')
// ->join('massage_service_user_list b','a.user_id = b.id')
// ->where($dis)
// ->where(function ($query) use ($mapor){
// $query->whereOr($mapor);
// })
// ->field('a.*,b.nickName,b.avatarUrl')
// ->group('a.id')
// ->order('a.integral desc,a.id desc')
// ->paginate($page)
// ->toArray();
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->join('shequshop_car_game c','a.id = c.record_id','left')
->where($dis)
->where('a.pay_type','>',1)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,c.best_time as best_time,b.nickName,b.avatarUrl')
->group('a.id')
->order(['a.integral desc','a.pay_type desc','c.best_time','a.id desc'])
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:记录列表
*/
public function recordList($dis,$page=10,$mapor=[]){
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->where($dis)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.nickName')
->group('a.id')
->order('a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-10-19 17:58
* @功能说明:获取排名
*/
public function getRecordTop($record){
$dis = [
'a.atv_id' => $record['atv_id']
];
$data = $this->alias('a')
->join('shequshop_car_game c','a.id = c.record_id')
->where($dis)
->field('a.id')
->group('a.id')
->order(['a.integral desc','a.pay_type desc','c.best_time','a.id desc'])
->select()
->toArray();
$top = 0;
if(!empty($data)){
foreach ($data as $k=>$v){
if($v['id']==$record['id']){
$top = $k+1;
}
}
}
return $top;
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:记录列表
*/
public function atvRecordList($dis,$page=10,$mapor=[],$rank = 2){
$top = $rank==2?'a.integral':'a.integral desc';
$data = $this->alias('a')
->join('shequshop_car_atv_list b','a.atv_id = b.id')
->join('shequshop_car_game c','a.id = c.record_id','left')
->where($dis)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.title,b.cover,b.atv_num,b.atv_status,c.best_time as best_time,c.major')
->group('a.id')
->order([$top,'a.pay_type desc','c.best_time','a.id desc'])
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-09-26 16:44
* @功能说明:支付回调
*/
public function dataResult($order_code,$transaction_id){
$data = $this->dataInfo(['order_code'=>$order_code]);
if($data['pay_type']==1){
//由于时效性问题 报名数量放到回调里面处理
// $atv_model = new CarAtvList();
//
// $atv = $atv_model->dataInfo(['id'=>$data['atv_id']]);
// //报名已经满了
// if($atv['atv_num']<=$atv['have_num']){
//
// $this
//
//
// //不再执行
// return true;
// }
//
//
// $atv_model->where(['id'=>$data['atv_id']])->update(['have_num'=>Db::raw("have_num+1")]);
$update = [
'pay_type' => 2,
'pay_time' => time(),
'transaction_id' => $transaction_id
];
$this->dataUpdate(['id'=>$data['id']],$update);
//余额扣除
if($data['balance']>0){
$user_model = new User();
$user = $user_model->dataInfo(['id'=>$data['user_id']]);
$balance = $user['balance'] - $data['balance'];
$user_model->dataUpdate(['id'=>$data['user_id']],['balance'=>$balance]);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-09-26 17:19
* @功能说明:取消超时未支付的
*/
public function autoCancelRecord($user_id=0){
if(!empty($user_id)){
$dis[] = ['user_id','=',$user_id];
}else{
$dis[] = ['over_time','<',time()];
}
$dis[] = ['pay_type','=',1];
$list = $this->where($dis)->select()->toArray();
if(!empty($list)){
foreach ($list as $value){
Db::startTrans();
$res = $this->cancelRecord($value,1);
if(!empty($res['code'])){
Db::rollback();
}
Db::commit();
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-09-26 17:19
* @功能说明:取消超时未支付的
*/
public function cancelRecord($record,$auto_refund=0){
$atv_model = new CarAtvList();
$update = [
'pay_type' => -1,
'refund_time' => time(),
'auto_refund' => $auto_refund,
];
$res = $this->dataUpdate(['id'=>$record['id']],$update);
if($res==0){
return ['code'=>500,'msg'=>'取消失败1'];
}
$atv = $atv_model->dataInfo(['id'=>$record['atv_id']]);
$res = $atv_model->dataUpdate(['id'=>$record['atv_id']],['have_num'=>$atv['have_num']-1]);
if($res==0){
return ['code'=>500,'msg'=>'取消失败'];
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-11-12 15:06
* @功能说明:积分到账
*/
public function pointSuccess($uniacid){
$dis = [
'pay_type' => 7,
'have_tx' => 0,
'uniacid' => $uniacid
];
$order = $this->where($dis)->field('id,integral,user_id,uniacid')->select()->toArray();
if(!empty($order)){
$integral_model = new \app\member\model\Integral();
foreach ($order as $value){
//修改订单状态
$res = $this->where(['id'=>$value['id'],'have_tx'=>0])->update(['have_tx'=>1]);
//增加用户积分
if($res==1){
$integral_model->integralUserAdd($value['user_id'],$value['integral'],$value['uniacid'],2,8,$value['id']);
}
}
}
return true;
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarDriver extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_driver';
/**
* @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,$mapor=[]){
// $data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->where($dis)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.nickName,avatarUrl')
->group('a.id')
->order('a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
}

View File

@@ -0,0 +1,209 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarGame extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_game';
protected $append = [
'start_time_text',
'best_time_text',
'total_time_text',
];
/**
* @author chenniang
* @DataTime: 2021-10-21 10:20
* @功能说明:转换时间格式
*/
public function getBestTimeTextAttr($value,$data){
if(!empty($data['best_time'])){
return game_time($data['best_time']);
}
}
/**
* @author chenniang
* @DataTime: 2021-10-21 10:20
* @功能说明:转换时间格式
*/
public function getTotalTimeTextAttr($value,$data){
if(!empty($data['total_time'])){
return game_time($data['total_time']);
}
}
/**
* @author chenniang
* @DataTime: 2021-09-28 11:48
* @功能说明:转换时间格式
*/
public function getStartTimeTextAttr($value,$data){
if(!empty($data['start_time'])){
return date('Y.m.d H:i',$data['start_time']);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page){
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:成绩排行版
*/
public function topRecordList($dis,$page=10,$mapor=[]){
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->where($dis)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.nickName,b.avatarUrl')
->group('a.id')
->order('a.best_time asc,a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-09-16 13:57
* @功能说明:成绩排行版(可根据时间)
*/
public function timeTopRecordList($dis,$page=10,$time = 1,$mapor=[]){
switch ($time){
case 1:
$time_text = 'today';
break;
case 2:
$time_text = 'week';
break;
case 3:
$time_text = 'month';
break;
case 4:
$time_text = 'year';
break;
}
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->where($dis)
->whereTime('a.start_time',$time_text)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,b.nickName,b.avatarUrl')
->group('a.id')
->order('a.best_time asc,a.id desc')
->paginate($page)
->toArray();
return $data;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarLineUp extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_line_up';
/**
* @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,83 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarPrice extends BaseModel
{
//定义表名
protected $name = 'massage_service_car_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: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,97 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarRecordContent extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_atv_record_content';
/**
* @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,$mapor=[]){
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
// $data = $this->alias('a')
// ->join('massage_service_user_list b','a.user_id = b.id')
// ->where($dis)
// ->where(function ($query) use ($mapor){
// $query->whereOr($mapor);
// })
// ->field('a.*,b.nickName')
// ->group('a.id')
// ->order('a.id desc')
// ->paginate($page)
// ->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarTrophy extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_trophy';
/**
* @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():[];
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarType extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_cartype';
/**
* @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():[];
}
/**
* @param $id
* @param $user
* @功能说明:判断类型 专业还是普通
* @author chenniang
* @DataTime: 2021-09-28 16:55
*/
public function getType($id,$user_id){
$data = $this->dataInfo(['id'=>$id]);
//如果动过数据库 一律判断为普通
if(empty($data)){
return 1;
}
//如果即选过 专业和普通 就判断用户当前身份
if(!empty($data['major'])&&!empty($data['norm'])){
$driver_model = new CarDriver();
$user = $driver_model->dataInfo(['user_id'=>$user_id,'status'=>2]);
if(!empty($user)){
return 2;
}else{
return 1;
}
}else{
//就根据车型身份勾选来
$res = !empty($data['major'])?2:1;
return $res;
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarTypeConnect extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_cartype_connect';
/**
* @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,108 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CarUserTrophy extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_user_trophy';
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page=10){
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-09-26 16:10
* @功能说明:用户荣誉杯
*/
public function userTrophy($user_id){
//查看荣誉杯
$dis = [
'a.user_id' => $user_id,
'a.status' => 1,
'b.status' => 1,
];
$data = $this->alias('a')
->join('shequshop_car_trophy b','a.trophy_id = b.id')
->where($dis)
->field('a.*,b.title,b.cover')
->select()
->toArray();
return $data;
}
}

View File

@@ -0,0 +1,287 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Comment extends BaseModel
{
//定义表名
protected $name = 'massage_service_order_comment';
protected $append = [
'lable_text',
'order_goods',
];
/**
* @author chenniang
* @DataTime: 2021-03-19 17:05
* @功能说明:子订单信息
*/
public function getOrderGoodsAttr($value,$data){
if(!empty($data['order_id'])){
$order_goods_model = new OrderGoods();
$dis = [
'order_id' => $data['order_id']
];
$list = $order_goods_model->where($dis)->select()->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-05 23:32
* @功能说明:标签列表
*/
public function getLableTextAttr($vaule,$data){
if(!empty($data['id'])){
$lable_model = new Lable();
$dis = [
'b.comment_id' => $data['id'],
'a.status' => 1
];
$list = $lable_model->alias('a')
->join('massage_service_comment_lable b','a.id = b.lable_id')
->where($dis)
->column('a.title');
return array_values($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->alias('a')
->join('massage_service_order_list b','a.order_id = b.id')
->join('massage_service_order_goods_list c','a.order_id = c.order_id')
->join('massage_service_coach_list d','b.coach_id = d.id')
->join('massage_service_user_list e','a.user_id = e.id')
->where($dis)
->field('a.*,e.nickName,e.avatarUrl,c.goods_name,c.goods_cover,c.num,c.price,d.coach_name')
->group('a.id')
->order('a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
if(empty($data)){
$this->dataAdd($dis);
$data = $this->where($dis)->find();
}
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-04-01 09:51
* @功能说明:公众号楼长端新订单通知
*/
public function sendMsg($order){
$cap_model = new Cap();
$cap_id = $order['cap_id'];
$uniacid = $order['uniacid'];
//获取楼长openid
$openid = $cap_model->capOpenid($cap_id);
$store_name = $cap_model->where(['id'=>$cap_id])->value('store_name');
$access_token = longbingGetAccessToken($uniacid);
$config = $this->dataInfo(['uniacid'=>$uniacid]);
$page = "master/pages/order/list";
//post地址
$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token={$access_token}";
$x_config = longbingGetAppConfig($uniacid);
$goods_data = '';
$num = count($order['order_goods'])-1;
foreach ($order['order_goods'] as $k=>$v){
$icon = $k==$num?'':',';
$goods_data .= $v['goods_name'].'x'.$v['goods_num'].$icon;
}
$order_text = !empty($order['text'])?','.$order['text']:'';
$address_data = $order['address_info'];
$data = [
//用户小程序openid
'touser' => $openid,
'mp_template_msg' => [
//公众号appid
'appid' => $config['app_id'],
"url" => "http://weixin.qq.com/download",
//公众号模版id
'template_id' => $config['tmp_id'],
'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' => $goods_data.$order_text,
'color' => '#0000ff',
),
'keyword3' => array(
//内容
'value' => $order['pay_price'].'元',
'color' => '#0000ff',
),
'keyword4' => array(
//内容
'value' => '送货上门',
'color' => '#0000ff',
),
'keyword5' => array(
'value' => $address_data['user_name'].','.$address_data['mobile'].','.$address_data['address'].$address_data['address_info'],
'color' => '#45818e',
),
'remark' => array(
//内容
'value' => $order['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;
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CommentLable extends BaseModel
{
//定义表名
protected $name = 'massage_service_comment_lable';
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page){
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
if(empty($data)){
$this->dataAdd($dis);
$data = $this->where($dis)->find();
}
return !empty($data)?$data->toArray():[];
}
}

View File

@@ -0,0 +1,354 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Commission extends BaseModel
{
//定义表名
protected $name = 'massage_service_order_commission';
protected $append = [
'order_goods'
];
public function getOrderGoodsAttr($value,$data){
if(!empty($data['id'])){
$order_goods_model = new CommissionGoods();
$list = $order_goods_model->goodsList(['a.commission_id'=>$data['id']]);
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-08-25 23:24
* @功能说明:记录
*/
public function recordList($dis,$page=10){
$data = $this->alias('a')
->join('massage_service_user_list b','a.user_id = b.id')
->join('massage_service_user_list c','a.top_id = c.id')
->join('massage_service_order_list d','a.order_id = d.id')
->where($dis)
->field('a.*,b.nickName,c.nickName as top_name,d.order_code,d.pay_type,d.pay_price,d.transaction_id')
->group('a.id')
->order('a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-08-25 23:34
* @功能说明:佣金到账
*/
public function successCash($order_id){
$data = $this->dataInfo(['order_id'=>$order_id]);
if(!empty($data)&&$data['status']==1){
$res = $this->dataUpdate(['id'=>$data['id']],['status'=>2]);
if($res==0){
return $res;
}
$user_model = new User();
$user = $user_model->dataInfo(['id'=>$data['top_id']]);
$res = $user_model->where(['id'=>$data['top_id'],'balance'=>$user['balance']])->update(['balance'=>$user['balance']+$data['cash'],'cash'=>$user['cash']+$data['cash']]);
if($res==0){
return $res;
}
}
return 1;
}
/**
* @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){
$data['update_time'] = time();
$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():[];
}
/**
* @author chenniang
* @DataTime: 2021-08-26 23:39
* @功能说明:添加佣金
*/
public function commissionAdd($order){
$user_model = new User();
//上级
$top = $user_model->where(['id'=>$order['user_id']])->value('pid');
if(!empty($top)){
$ser_model = new Service();
$com_mdoel = new Commission();
$com_goods_mdoel = new CommissionGoods();
foreach ($order['order_goods'] as $v){
//查看是否有分销
$ser = $ser_model->dataInfo(['id'=>$v['goods_id']]);
if(!empty($ser['com_balance'])){
$insert = [
'uniacid' => $order['uniacid'],
'user_id' => $order['user_id'],
'top_id' => $top,
'order_id'=> $order['id'],
'order_code' => $order['order_code'],
];
$find = $com_mdoel->dataInfo($insert);
$cash = $v['true_price']*$ser['com_balance']/100*$v['num'];
if(empty($find)){
$insert['cash'] = $cash;
$com_mdoel->dataAdd($insert);
$id = $com_mdoel->getLastInsID();
}else{
$id = $find['id'];
$update = [
'cash' => $find['cash']+$cash
];
//加佣金
$com_mdoel->dataUpdate(['id'=>$find['id']],$update);
}
$insert = [
'uniacid' => $order['uniacid'],
'order_goods_id' => $v['id'],
'commission_id' => $id,
'cash' => $cash,
'num' => $v['num'],
'balance' => $ser['com_balance']
];
//添加到自订单记录表
$res = $com_goods_mdoel->dataAdd($insert);
}
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-08-28 14:35
* @功能说明:佣金到账
*/
public function successCommission($order_id){
$comm = $this->dataInfo(['order_id'=>$order_id,'status'=>1]);
if(!empty($comm)){
$user_model = new User();
$user = $user_model->dataInfo(['id'=>$comm['top_id']]);
if(!empty($user)){
$update = [
'balance' => $user['balance']+$comm['cash'],
'cash' => $user['cash']+$comm['cash'],
];
$user_model->dataUpdate(['id'=>$comm['top_id']],$update);
$this->dataUpdate(['id'=>$comm['id']],['status'=>2,'cash_time'=>time()]);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-08-28 14:48
* @功能说明:退款的时候要减去分销
*/
public function refundComm($refund_id){
$refund_model = new RefundOrder();
$com_goods_mdoel = new CommissionGoods();
$refund_order = $refund_model->dataInfo(['id'=>$refund_id]);
if(!empty($refund_order)){
//查询这笔等待有无佣金
$comm = $this->dataInfo(['order_id'=>$refund_order['order_id'],'status'=>1]);
if(!empty($comm)){
foreach ($refund_order['order_goods'] as $v){
$comm_goods = $com_goods_mdoel->dataInfo(['commission_id'=>$comm['id'],'order_goods_id'=>$v['order_goods_id']]);
$comm_goods_cash = $comm_goods['cash']/$comm_goods['num'];
$true_num = $comm_goods['num'] - $v['num'];
$true_num = $true_num>0?$true_num:0;
$update = [
'num' => $true_num,
'cash'=> $comm_goods_cash*$true_num
];
$com_goods_mdoel->dataUpdate(['id'=>$comm_goods['id']],$update);
}
$total_cash = $com_goods_mdoel->where(['commission_id'=>$comm['id']])->sum('cash');
$update = [
'cash' => $total_cash,
'status' => $total_cash>0?1:-1
];
$this->dataUpdate(['id'=>$comm['id']],$update);
}
}
return true;
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CommissionGoods extends BaseModel
{
//定义表名
protected $name = 'massage_service_order_commission_goods';
/**
* @author chenniang
* @DataTime: 2021-08-25 23:19
* @功能说明:
*/
public function goodsList($dis){
$data = $this->alias('a')
->join('massage_service_order_goods_list b','a.order_goods_id = b.id')
->where($dis)
->field('a.*,b.goods_name,b.goods_cover,b.true_price')
->group('a.id')
->select()
->toArray();
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=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,84 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Config extends BaseModel
{
//定义表名
// protected $name = 'lbfarm_config';
protected $name = 'lbfarm_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,628 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\member\model\Level;
use think\facade\Db;
class Coupon extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon';
protected $append = [
'service',
'send_count',
'member_level',
'shop_goods',
'restaurant_goods'
];
/**
* @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: 2021-07-11 01:54
* @功能说明:
*/
public function getServiceAttr($value,$data){
if(!empty($data['id'])){
$ser_model = new Goods();
$dis = [
'a.status' => 1,
'b.coupon_id' => $data['id'],
'b.type' => 0,
'b.scene' => 1
];
$list = $ser_model->alias('a')
->join('massage_service_coupon_goods b','b.goods_id = a.id')
->where($dis)
->field('a.id,a.title,a.price,b.goods_id,a.cover')
->group('a.id')
->order('a.top desc,a.id desc')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-11 01:54
* @功能说明:
*/
public function getShopGoodsAttr($value,$data){
if(!empty($data['id'])){
$ser_model = new \app\shop\model\Goods();
$dis = [
'a.status' => 1,
'b.coupon_id' => $data['id'],
'b.type' => 0,
'b.scene' => 2
];
$list = $ser_model->alias('a')
->join('massage_service_coupon_goods b','b.goods_id = a.id')
->where($dis)
->field('a.id,a.name,b.goods_id,a.cover')
->group('a.id')
->order('a.top desc,a.id desc')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-11 01:54
* @功能说明:
*/
public function getRestaurantGoodsAttr($value,$data){
if(!empty($data['id'])){
$ser_model = new \app\restaurant\model\Goods();
$dis = [
'a.status' => 1,
'b.coupon_id' => $data['id'],
'b.type' => 0,
'b.scene' => 3
];
$list = $ser_model->alias('a')
->join('massage_service_coupon_goods b','b.goods_id = a.id')
->where($dis)
->field('a.id,a.title,b.goods_id,a.cover')
->group('a.id')
->order('a.id desc')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-11 01:54
* @功能说明:
*/
public function getMemberLevelAttr($value,$data){
if(!empty($data['id'])){
$level_model = new Level();
$dis = [
'a.status' => 1,
'b.coupon_id' => $data['id'],
];
$list = $level_model->alias('a')
->join('longbing_card_v2_coupon_connect b','b.member_level = a.id')
->where($dis)
->field('a.id,a.title')
->group('a.id')
->order('a.id desc')
->column('a.id');
return array_values($list);
}
}
/**
* @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']);
}
if(isset($data['restaurant_goods'])){
unset($data['restaurant_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,$scene=1){
// $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 as $vs){
// if(in_array($vs['goods_list'],$goods_id)){
$price += $v['true_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($info['start_time']<time()&&$info['end_time']>time()){
$p_coupon_id = !empty($info['pid'])?$info['pid']:$coupon_id;
$can_discount_price = $this->getDicountPrice($order_goods['list'],$p_coupon_id,$scene);
//是否满足满减条件
if($info['full']>$can_discount_price['discount']||$can_discount_price['discount']==0){
return $order_goods;
}
$total_discount = 0;
foreach ($order_goods['list'] as $vs){
foreach ($vs as &$v){
//如果该商品可以使用优惠券
if(in_array($v['goods_id'],$can_discount_price['goods_id'])){
$bin = $v['true_price']/$can_discount_price['discount'];
//该商品减去的折扣
$discount = $bin*$info['discount']<$v['true_price']?$bin*$info['discount']:$v['true_price'];
//总计折扣
$total_discount+=$discount;
$v['true_price'] = round($v['true_price']-$discount,2);
}
}
}
$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,$type=1,$is_show=1,$no_i=1,$table_id=0){
$coupon_model = new CouponRecord();
$coupon_model->where(['user_id'=>$user_id,'status'=>1])->where('end_time','<',time())->update(['status'=>3]);
$list = $coupon_model->where(['user_id'=>$user_id,'status'=>1])->order('id desc')->select()->toArray();
if($type==1){
$car_model = new Car();
//获取购物车里面的信息
$car_list = $car_model->carPriceAndCount($user_id,1);
}else{
if($type==2){
$car_model = new \app\shop\model\Car();
//获取购物车里面的信息
$car_list = $car_model->carPriceAndCount($user_id,1,1,$is_show,$no_i);
}else{
$car_model = new \app\restaurant\model\Car();
$car_list = $car_model->carPriceAndCount($user_id,2,$table_id);
}
}
$car_list = $car_list['list'];
$data = [];
if(!empty($list)){
foreach ($list as &$v){
if($v['start_time']<time()&&$v['end_time']>time()){
$id = !empty($v['pid'])?$v['pid']:$v['id'];
$info = $this->getDicountPrice($car_list,$id,$type);
if($v['full']<=$info['discount']&&$info['discount']>0){
$data[] = $v['id'];
}
}
}
}
return $data;
}
/**
* @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,356 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponAtv extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_atv';
protected $append = [
'coupon'
];
/**
* @author chenniang
* @DataTime: 2021-03-23 13:46
* @功能说明:分类下面端商品数量
*/
public function getCouponAttr($value,$data){
if(!empty($data['id'])){
$coupom_model = new Coupon();
$dis = [
'a.status' => 1,
'b.atv_id' => $data['id']
];
$list = $coupom_model->alias('a')
->join('massage_service_coupon_atv_coupon b','b.coupon_id = a.id')
->where($dis)
->field('a.*,b.num,b.coupon_id')
->group('b.coupon_id')
->order('a.top desc,id desc')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$service = $data['coupon'];
unset($data['coupon']);
$res = $this->insert($data);
$id = $this->getLastInsID();
$this->updateSome($id,$data['uniacid'],$service);
return $id;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
// $data['update_time'] = time();
if(isset($data['coupon'])){
$service = $data['coupon'];
unset($data['coupon']);
}
$res = $this->where($dis)->update($data);
if(!empty($service)){
$id = $this->where($dis)->value('id');
$this->updateSome($id,$data['uniacid'],$service);
}
return $res;
}
/**
* @param $id
* @param $uniacid
* @param $spe
* @功能说明:
* @author chenniang
* @DataTime: 2021-03-23 13:35
*/
public function updateSome($id,$uniacid,$coupon){
$s_model = new CouponAtvCoupon();
$s_model->where(['atv_id'=>$id])->delete();
if(!empty($coupon)){
foreach ($coupon as $value){
$insert['uniacid'] = $uniacid;
$insert['atv_id'] = $id;
$insert['coupon_id'] = $value['id'];
$insert['num'] = $value['num'];
$s_model->dataAdd($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();
if(empty($data)){
$this->insert($dis);
$data = $this->where($dis)->find();
}
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-07-12 17:52
* @功能说明:优惠券活动邀请新用户
*/
public function invUser($user_id,$record_id){
$atv_record_model = new CouponAtvRecord();
$atv_record_list_model = new CouponAtvRecordList();
$record = $atv_record_model->dataInfo(['id'=>$record_id]);
Db::startTrans();
if(!empty($record)&&$record['end_time']>time()&&$record['status']==1){
$insert = [
'uniacid' => $record['uniacid'],
'user_id' => $record['user_id'],
'to_inv_id'=> $user_id,
'record_id'=> $record_id
];
//添加邀请者记录
$res = $atv_record_list_model->dataAdd($insert);
if(!empty($res['code'])){
Db::rollback();
return ['code'=>500,'msg'=>'登陆失败,请刷新重试'];
}
//新用户获得卡券
if($record['to_inv_user']==1&&!empty($record['coupon'])){
$res = $this->giveAtvCoupon($record_id,$user_id);
if(!empty($res['code'])){
Db::rollback();
return $res;
}
}
//检查任务是否完成
$res = $this->recordSuccess($record_id);
if(!empty($res['code'])){
Db::rollback();
return $res;
}
}
Db::commit();
return true;
}
/**
* @author chenniang
* @DataTime: 2021-07-13 00:07
* @功能说明:给用户获得卡券
*/
public function giveAtvCoupon($record_id,$user_id){
$atv_record_model = new CouponAtvRecord();
$record_model = new CouponRecord();
$atv_record_coupon_model = new CouponAtvRecordCoupon();
$record = $atv_record_model->dataInfo(['id'=>$record_id]);
foreach ($record['coupon'] as $value){
//派发卡券
// $num = $value['stock']>=$value['num']?$value['num']:$value['stock'];
$num = $value['num'];
if($num>0){
$res = $record_model->recordAdd($value['coupon_id'],$user_id,$num);
if($res==0){
return ['code'=>500,'msg'=>'登陆失败,请刷新重试'];
}
//添加派发记录
$insert = [
'uniacid' => $record['uniacid'],
'user_id' => $user_id,
'atv_id' => $record['atv_id'],
'coupon_id' => $value['coupon_id'],
'num' => $value['num'],
'status' => 2,
'success_num' => $num
];
$res = $atv_record_coupon_model->dataAdd($insert);
if($res==0){
return ['code'=>500,'msg'=>'登陆失败,请刷新重试'];
}
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-07-12 23:46
* @功能说明:获得成功
*/
public function recordSuccess($record_id){
$atv_record_list_model = new CouponAtvRecordList();
$atv_record_model = new CouponAtvRecord();
//已经邀请多少人了
$have_num = $atv_record_list_model->where(['record_id'=>$record_id])->count();
$record = $atv_record_model->dataInfo(['id'=>$record_id]);
//如果成功
if($have_num>=$record['inv_user_num']){
//修改获得状态
$res = $atv_record_model->dataUpdate(['id'=>$record['id'],'status'=>1],['status'=>2]);
if($res==0){
return ['code'=>500,'msg'=>'登陆失败,请刷新重试'];
}
if($record['inv_user']==1){
//给发起者派送卡券
$res = $this->giveAtvCoupon($record_id,$record['user_id']);
if(!empty($res['code'])){
return $res;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponAtvCoupon extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_atv_coupon';
/**
* @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-03-17 15:23
* @功能说明:通过
*/
public function subSh($id,$goods_id){
$goods_list_model = new GoodsShList();
$goods_model = new Goods();
$list = $goods_model->where('id','in',$goods_id)->select()->toArray();
Db::startTrans();
foreach ($list as $value){
$insert = [
'uniacid' => $value['uniacid'],
'sh_id' => $id,
'goods_id' => $value['id'],
'goods_name' => $value['goods_name'],
'cover' => $value['cover'],
'imgs' => !empty($value['imgs'])?implode(',',$value['imgs']):'',
'text' => $value['text'],
'cate_id' => $value['cate_id'],
];
//添加到审核商品表
$res = $goods_list_model->dataAdd($insert);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'提交失败'];
}
$goods_sh_id = $goods_list_model->getLastInsID();
if(!empty($value['spe'])){
foreach ($value['spe'] as $v){
$insert = [
'uniacid' => $v['uniacid'],
'sh_goods_id' => $goods_sh_id,
'title' => $v['title'],
'stock' => $v['stock'],
'price' => $v['price'],
'spe_id' => $v['id'],
];
//添加审核规格表
$res = Db::name('shequshop_school_goods_sh_spe')->insert($insert);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'提交失败'];
}
}
}
}
//将商品状态改为审核中
$goods_model->where('id','in',$goods_id)->update(['status'=>4]);
Db::commit();
return true;
}
/**
* @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)->count();
return $data;
}
}

View File

@@ -0,0 +1,199 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponAtvRecord extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_atv_record';
protected $append = [
'coupon'
];
/**
* @author chenniang
* @DataTime: 2021-07-12 23:06
* @功能说明:派发的优惠券
*/
public function getCouponAttr($value,$data){
if(!empty($data['id'])){
$list_model = new CouponAtvRecordCoupon();
$dis = [
'a.record_id' => $data['id'],
'a.user_id' => 0,
// 'b.status' => 1
];
$list = $list_model->alias('a')
->join('massage_service_coupon b','a.coupon_id = b.id')
->where($dis)
->where('b.status','>',-1)
->field('a.*,b.title,b.stock,b.i')
->group('a.coupon_id')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-19 10:47
* @功能说明:判断卡券是否参加活动
*/
public function couponIsAtv($coupon_id){
$dis_where[] = ['status','=',1];
$dis_where[] = ['end_time','<',time()];
//修改过期状态
$this->dataUpdate($dis_where,['status'=>3]);
$dis = [
//活动进行中
'a.status' => 1,
'b.coupon_id' => $coupon_id
];
$data = $this->alias('a')
->join('massage_service_coupon_atv_record_coupon b','a.id = b.record_id')
->where($dis)
->count();
return !empty($data)?true:false;
}
/**
* @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-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)->count();
return $data;
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponAtvRecordCoupon extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_atv_record_coupon';
/**
* @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)->count();
return $data;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponAtvRecordList extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_atv_record_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: 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->alias('a')
->join('massage_service_user_list b','b.id = a.to_inv_id')
->where($dis)
->field('b.nickName,b.avatarUrl,b.id,a.create_time')
->group('b.id')
->paginate($page)
->toArray();
if(!empty($data['data'])){
foreach ($data['data'] as &$v){
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
}
}
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,101 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponMember extends BaseModel
{
//定义表名
protected $name = 'longbing_card_v2_coupon_connect';
/**
* @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-11-01 15:43
* @功能说明:优惠券
*/
public function eventCoupon($id,$data){
if(!empty($data['member_level'])){
foreach ($data['member_level'] as $value){
$insert['uniacid'] = $data['uniacid'];
$insert['coupon_id'] = $id;
$insert['member_level'] = $value;
$this->dataAdd($insert);
}
}
return true;
}
}

View File

@@ -0,0 +1,534 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\member\model\Level;
use think\facade\Db;
class CouponRecord extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_record';
protected $append = [
'goods',
'shop_goods',
'restaurant_goods'
];
/**
* @author chenniang
* @DataTime: 2021-07-11 01:54
* @功能说明:
*/
public function getGoodsAttr($value,$data){
if(!empty($data['id'])){
$id = !empty($data['pid'])?$data['pid']:$data['id'];
$ser_model = new Goods();
$dis = [
'a.status' => 1,
'b.coupon_id' => $id,
'b.type' => 1,
'b.scene' => 1,
];
$list = $ser_model->alias('a')
->join('massage_service_coupon_goods b','b.goods_id = a.id')
->where($dis)
->field('a.id,a.title,a.price,b.goods_id')
->group('a.id')
->order('a.top desc,a.id desc')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-11 01:54
* @功能说明:
*/
public function getShopGoodsAttr($value,$data){
if(!empty($data['id'])){
$id = !empty($data['pid'])?$data['pid']:$data['id'];
$ser_model = new \app\shop\model\Goods();
$dis = [
'a.status' => 1,
'b.coupon_id' => $id,
'b.type' => 1,
'b.scene' => 2,
];
$list = $ser_model->alias('a')
->join('massage_service_coupon_goods b','b.goods_id = a.id')
->where($dis)
->field('a.id,a.name,b.goods_id')
->group('a.id')
->order('a.top desc,a.id desc')
->select()
->toArray();
return $list;
}
}
/**
* @author chenniang
* @DataTime: 2021-07-11 01:54
* @功能说明:
*/
public function getRestaurantGoodsAttr($value,$data){
if(!empty($data['id'])){
$id = !empty($data['pid'])?$data['pid']:$data['id'];
$ser_model = new \app\restaurant\model\Goods();
$dis = [
'a.status' => 1,
'b.coupon_id' => $id,
'b.type' => 1,
'b.scene' => 3,
];
$list = $ser_model->alias('a')
->join('massage_service_coupon_goods b','b.goods_id = a.id')
->where($dis)
->field('a.id,a.title,b.goods_id')
->group('a.id')
->order('a.id desc')
->select()
->toArray();
return $list;
}
}
/**
* @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){
$coupon_model = new Coupon();
$coupon = $coupon_model->dataInfo(['id'=>$coupon_id]);
//用户自己领取的优惠券
if($user_get==1){
if($coupon['send_type']!=2){
return ['code'=>500,'msg'=>'优惠券已下架'];
}
$user_model = new User();
$user_info = $user_model->dataInfo(['id'=>$user_id]);
$level = $coupon['member_level'];
if(!in_array($user_info['member_level'],$level)){
$level_model = new Level();
$level_title = $level_model->where('id','in',$level)->column('title');
$level_title = !empty($level_title)?implode(',',$level_title):'';
return ['code'=>50002,'msg'=>'只有'.$level_title.'等级的会员才能领取'];
}
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'],
'num' => $num,
'start_time'=> $coupon['time_limit']==1?time():$coupon['start_time'],
'end_time' => $coupon['time_limit']==1?time()+$coupon['day']*86400:$coupon['end_time'],
];
$res = $this->dataAdd($insert);
if($res==0){
return $res;
}
$record_id = $this->getLastInsID();
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 $res;
}
}
$list = [
1 => $coupon['service'],
2 => $coupon['shop_goods'],
3 => $coupon['restaurant_goods'],
];
$coupon_goods_model = new CouponService();
//给优惠券添加限用商品等
foreach ($list as $ks=>$vs){
if(!empty($vs)){
foreach ($vs as $vv){
$insert = [
'uniacid' => $coupon['uniacid'],
'type' => 1,
'goods_id' => $vv['goods_id'],
'coupon_id'=> $record_id,
'scene' => $ks
];
$res = $coupon_goods_model->insert($insert);
}
}
}
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){
$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;
$this->insert($record);
$coupon_id = $this->getLastInsID();
}else{
$this->dataUpdate(['id'=>$coupon_id],['status'=>2,'use_time'=>time(),'order_id'=>$order_id]);
}
return $coupon_id;
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class CouponService extends BaseModel
{
//定义表名
protected $name = 'massage_service_coupon_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 goodsUpdate($dis,$data){
$spe = $data['spe'];
unset($data['spe']);
$res = $this->where($dis)->update($data);
$this->updateSome($dis['id'],$data['uniacid'],$spe);
return $res;
}
/**
* @param $id
* @param $uniacid
* @param $spe
* @功能说明:
* @author chenniang
* @DataTime: 2021-03-23 13:35
*/
public function updateSome($id,$uniacid,$coach){
$spe_model = new GoodsSpe();
$spe_model->where(['goods_id'=>$id])->delete();
if(!empty($spe)){
foreach ($spe as $value){
$value['uniacid'] = $uniacid;
$value['goods_id'] = $id;
$spe_model->dataAdd($value);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page){
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-11-01 15:43
* @功能说明:优惠券
*/
public function eventCoupon($id,$data){
if(!empty($data['service'])){
foreach ($data['service'] as $value){
$insert['uniacid'] = $data['uniacid'];
$insert['coupon_id'] = $id;
$insert['goods_id'] = $value;
$this->dataAdd($insert);
}
}
return true;
}
}

358
app/massage/model/Goods.php Normal file
View File

@@ -0,0 +1,358 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Goods extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_goods';
protected $append = [
'create_time_text',
'car_type'
];
/**
* @author chenniang
* @DataTime: 2021-09-22 10:53
* @功能说明:
*/
public function getCarTypeAttr($value,$data){
if(!empty($data['id'])){
$car_connect_type = new CarTypeConnect();
$dis = [
'order_goods_id' => 0,
'goods_id' => $data['id']
];
$list = $car_connect_type->where($dis)->column('type_id');
return array_values($list);
}
}
/**
* @author chenniang
* @DataTime: 2021-10-12 14:17
* @功能说明:判断该车型是否在使用
*/
public function carTypeHave($car_type_id){
$dis [] = ['a.status','>',-1];
$dis [] = ['b.type_id','>',$car_type_id];
$data = $this->alias('a')
->join('shequshop_car_cartype_connect b','a.id = b.goods_id')
->where($dis)
->find();
return !empty($data)?$data->toArray():[];
}
/**
* @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 11:12
* @功能说明:
*/
public function getCreateTimeTextAttr($value,$data){
if(!empty($data['create_time'])){
return date('Y-m-d H:i:s',$data['create_time']);
}
}
/**
* @author chenniang
* @DataTime: 2021-09-22 10:46
* @功能说明:添加车型
*/
public function updateSome($car_type,$id,$uniacid){
$car_connect_type = new CarTypeConnect();
$dis = [
'order_goods_id' => 0,
'goods_id' => $id
];
$car_connect_type->where($dis)->delete();
if(!empty($car_type)){
foreach ($car_type as $k=> $value){
$insert[$k]['goods_id'] = $id;
$insert[$k]['uniacid'] = $uniacid;
$insert[$k]['type_id'] = $value;
}
$car_connect_type->saveAll($insert);
}
return true;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
if(isset($data['car_type'])){
$car_type = $data['car_type'];
unset($data['car_type']);
}
// $data['imgs'] = !empty($data['imgs'])?implode(',',$data['imgs']):'';
$res = $this->insert($data);
if(!empty($car_type)){
$id = $this->getLastInsID();
$this->updateSome($car_type,$id,$data['uniacid']);
}
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
if(isset($data['car_type'])){
$car_type = $data['car_type'];
unset($data['car_type']);
}
$res = $this->where($dis)->update($data);
if(!empty($car_type)){
$this->updateSome($car_type,$data['id'],$data['uniacid']);
}
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:06
* @功能说明:列表
*/
public function indexDataList($dis,$page,$sort){
$data = $this->where($dis)->order("$sort,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-07 10:21
* @功能说明:服务技师列表
*/
public function serviceCoachList($dis){
$data = $this->alias('a')
->join('massage_service_service_coach b','a.id = b.ser_id')
->where($dis)
->field(['a.*'])
->order('a.id desc')
->select()
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-03-18 10:07
* @功能说明:增加|减少库存 增加|减少销量
*/
public function setOrDelStock($goods_id,$num,$type=2){
if(empty($goods_id)){
return true;
}
$goods_info = $this->dataInfo(['id'=>$goods_id]);
//退货
if($type==1){
$update = [
'true_sale' => $goods_info['true_sale']-$num,
'total_sale'=> $goods_info['total_sale']-$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'=>'提交失败'];
}
}else{
$update = [
'true_sale' => $goods_info['true_sale']+$num,
'total_sale'=> $goods_info['total_sale']+$num,
'lock' => $goods_info['lock']+1,
];
//增加销量
$res = $this->where(['id'=>$goods_id,'lock'=>$goods_info['lock']])->update($update);
if($res!=1){
return ['code'=>500,'msg'=>'提交失败'];
}
}
return true;
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class GoodsSpe extends BaseModel
{
//定义表名
protected $name = 'shequshop_school_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('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,94 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Lable extends BaseModel
{
//定义表名
protected $name = 'massage_service_lable';
//
// public function getCreateTimeAttr($value,$data){
//
// if(!empty($value)){
//
// return date('Y-m-d H:i:s',$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('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,91 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Machine extends BaseModel
{
//定义表名
protected $name = 'lbfarm_machine';
/**
* @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,105 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class NoticeList extends BaseModel
{
//定义表名
protected $name = 'massage_service_notice_list';
/**
* @author chenniang
* @DataTime: 2021-07-16 10:44
* @功能说明:
*/
public function getCreateTimeAttr($value,$data){
if(!empty($value)){
return date('Y-m-d H:i:s',$value);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($uniacid,$order_id,$type=1){
$data['uniacid'] = $uniacid;
$data['order_id'] = $order_id;
$data['type'] = $type;
$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();
if(empty($data)){
$this->dataAdd($dis);
$data = $this->where($dis)->find();
}
return !empty($data)?$data->toArray():[];
}
}

1018
app/massage/model/Order.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,137 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class OrderAddress extends BaseModel
{
//定义表名
protected $name = 'massage_service_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('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 10:34
* @功能说明:添加下单地址
*/
public function orderAddressAdd($address_id,$order_id){
if(empty($address_id)){
return ['code'=>500,'msg'=>'请选择下单地址'];
}
$address_model = new Address();
$address = $address_model->dataInfo(['id'=>$address_id]);
if(empty($address)){
return ['code'=>500,'msg'=>'下单地址已删除'];
}
$insert = [
'uniacid' => $address['uniacid'],
'order_id' => $order_id,
'user_name'=> $address['user_name'],
'mobile' => $address['mobile'],
'province' => $address['province'],
'city' => $address['city'],
'area' => $address['area'],
'lng' => $address['lng'],
'lat' => $address['lat'],
'address' => $address['address'],
'address_info' => $address['address_info'],
];
$res = $this->dataAdd($insert);
if($res!=1){
return ['code'=>500,'msg'=>'下单失败'];
}
return $res;
}
}

View File

@@ -0,0 +1,260 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class OrderGoods extends BaseModel
{
//定义表名
protected $name = 'shequshop_car_order_goods';
protected $append = [
'refund_num'
];
/**
* @param $value
* @param $data
* @功能说明:获取退款的数量
* @author chenniang
* @DataTime: 2021-04-12 10:46
*/
public function getRefundNumAttr($value,$data){
if(!empty($data['id'])){
$refund_model = new RefundOrder();
$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){
$goods_model = new Goods();
$car_model = new Car();
foreach ($order_goods as $v){
// $ser_status = $goods_model->where(['id'=>$v['goods_id']])->value('status');
$goods = $goods_model->dataInfo(['id'=>$v['goods_id']]);
if($goods['status']!=1){
return ['code'=>500,'msg'=>'商品已经下架'];
}
$res = $this->checkIdentity($goods,$user_id);
if(!empty($res['code'])){
return $res;
}
$insert = [
'uniacid' => $v['uniacid'],
'order_id' => $order_id,
'user_id' => $user_id,
'pay_type' => 1,
'goods_name' => $v['title'],
'goods_cover' => $v['cover'],
'goods_price' => $v['price'],
'true_price' => round($v['true_price']/$v['num'],5),
'pay_price' => round($v['true_price'],2),
'num' => $v['num'],
'can_refund_num' => $v['num'],
'goods_id' => $v['goods_id'],
'circle' => $goods['number'],
'car_type_id' => $goods['car_type_id'],
];
$res = $this->dataAdd($insert);
if($res!=1){
return ['code'=>500,'msg'=>'下单失败'];
}
$order_goods_id = $this->getLastInsID();
$this->updateSome($v,$order_goods_id);
}
//删除购物车
$res = $car_model->where(['user_id'=>$user_id,'status'=>1])->delete();
return true;
}
/**
* @author chenniang
* @DataTime: 2021-09-23 17:33
* @功能说明:检查购买者身份
*/
public function checkIdentity($goods,$user_id){
$driver_model = new CarDriver();
//查看是否是专业赛车手
$info = $driver_model->dataInfo(['user_id'=>$user_id,'status'=>2]);
$car_type_model = new CarType();
$car_type = $car_type_model->dataInfo(['id'=>$goods['car_type_id']]);
if(!empty($info)&&empty($car_type['major'])){
return ['code'=>500,'msg'=>$goods['title'].'只有普通车手可购买'];
}
if(empty($info)&&empty($car_type['norm'])){
return ['code'=>50001,'msg'=>$goods['title'].'只有专业车手可购买'];
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-09-22 10:46
* @功能说明:添加车型
*/
public function updateSome($order_goods,$order_goods_id){
$car_connect_type = new CarTypeConnect();
$car_type = $car_connect_type->where(['order_goods_id'=>0,'goods_id'=>$order_goods['goods_id']])->column('type_id');
if(!empty($car_type)){
foreach ($car_type as $k=> $value){
$insert[$k]['goods_id'] = $order_goods['goods_id'];
$insert[$k]['uniacid'] = $order_goods['uniacid'];
$insert[$k]['order_goods_id'] = $order_goods_id;
$insert[$k]['type_id'] = $value;
}
$car_connect_type->saveAll($insert);
}
return true;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace app\massage\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():[];
}
}

View File

@@ -0,0 +1,442 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\restaurant\model\Table;
use think\facade\Db;
class Printer extends BaseModel
{
//定义表名
protected $name = 'massage_service_printer';
/**
* @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: 2020-11-11 09:25
* @功能说明:订单打印
*/
public function userOrder($id){
$order_model = new Order();
//订单信息
$order = $order_model->dataInfo(['id'=>$id]);
$brs = "<BR>";
$orderInfo = '<CB>'.'订单小票'.'</CB><BR>';
$orderInfo .= '--------------------------------'.$brs;
$orderInfo .= '服务/数量/价格'.$brs;
$orderInfo .= '--------------------------------'.$brs;
foreach ($order['order_goods'] as $v) {
$v['goods_name'] = mb_convert_encoding($v['goods_name'], "UTF-8", "auto");
$orderInfo .= $v['goods_name'].$brs;
$orderInfo .= ' X'.$v['num'].' '.round($v['true_price']*$v['num'],2).'元'.$brs;
// $orderInfo .= round($v['true_price']*$v['num'],2).'元'.$brs;
$orderInfo .= ''.$brs;
$orderInfo .= ''.$brs;
}
$coach_model = new Coach();
$address_model = new OrderAddress();
$coach_name = $coach_model->where(['id'=>$order['coach_id']])->value('coach_name');
$user_name = $address_model->where(['order_id'=>$order['id']])->value('user_name');
$orderInfo .= '预约技师:'.$coach_name.$brs;
$orderInfo .= '下单人:'.$user_name.$brs;
$time = date('Y-m-d H:i',$order['start_time']).'-'.date('Y-m-d H:i',$order['end_time']);
$orderInfo .= '预约时间:'.$time.$brs;
$orderInfo .= '预约金额:'.round($order['pay_price'],2).$brs;
$orderInfo .= '付款时间:'.date('Y-m-d H:i',$order['pay_time']).$brs;
return $orderInfo;
}
/**
* @author chenniang
* @DataTime: 2020-11-11 10:20
* @功能说明:打印
*/
public function orderPrinter($orderInfo,$aotu=1,$type=1){
$dis = [
'status' => 1,
];
if($aotu==1){
$dis['auto'] =1;
}
if($type==1){
$dis['is_car'] = 1;
}elseif($type==2){
$dis['is_shop'] = 1;
}else{
$dis['is_restaurant'] = 1;
}
$printer_config = $this->where($dis)->select()->toArray();
if(!empty($printer_config)){
foreach ($printer_config as $value){
$value['ukey'] = $value['api_key'];
$value['sn'] = $value['printer_key'];
//用户小票
$res = \longbingcore\printer\Printer::FeiePrintMsg($value,$orderInfo,'Open_printMsg',$value['user_ticket_num']);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2020-11-12 09:57
* @功能说明:打印
*
* type 1赛车 2商城 3 餐饮
*/
public function printer($id,$aotu=1,$type=1){
if($type==1){
$user_order = $this->carOrder($id);
}elseif ($type==2){
$user_order = $this->shopOrder($id);
}else{
$user_order = $this->restaurantOrder($id);
}
//打印
$res = $this->orderPrinter($user_order,$aotu,$type);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-11-11 09:25
* @功能说明:商城订单打印
*/
public function shopOrder($id){
$order_model = new \app\shop\model\Order();
//订单信息
$order = $order_model->dataInfo(['id'=>$id]);
$brs = "<BR>";
$orderInfo = '<CB>'.'商城订单小票'.'</CB><BR>';
$orderInfo .= '订单号:'.$order['order_code'].$brs;
$orderInfo .= '下单时间:'.date('Y-m-d H:i:s',$order['create_time']).$brs;
$orderInfo .= '--------------------------------'.$brs;
$orderInfo .= '商品/规格/数量/价格'.$brs;
$orderInfo .= '--------------------------------'.$brs;
foreach ($order['order_goods'] as $v) {
$v['goods_name'] = mb_convert_encoding($v['goods_name'], "UTF-8", "auto");
$orderInfo .= $v['goods_name'].$brs;
$orderInfo .= '【'.$v['spe_name'].'】'.$brs;
$orderInfo .= ' X'.$v['goods_num'].' '.round($v['pay_price'],2).'元'.$brs;
$orderInfo .= ''.$brs;
$orderInfo .= ''.$brs;
}
$orderInfo .= '--------------------------------'.$brs;
if($order['send_type']==1){
$orderInfo .= '配送方式:自提'.$brs;
}else{
$orderInfo .= '配送方式:快递'.$brs;
$orderInfo .= '物流费:'.$order['freight'].$brs;
$orderInfo .= ''.$brs;
$orderInfo .= ''.$brs;
}
$orderInfo .= '原价:'.$order['init_price'].$brs;
$orderInfo .= '优惠:'.round($order['init_price']-$order['pay_price'],2).$brs;
$orderInfo .= '实付:'.$order['pay_price'].$brs;
$address_model = new OrderAddress();
$user = $address_model->dataInfo(['order_id'=>$order['id'],'type'=>2]);
//自提
$orderInfo .= $user['address'].$user['address_info'].$brs;
$orderInfo .= $user['user_name'].' '.$user['mobile'].$brs;
$orderInfo .= '备注:'.$order['text'].$brs;
return $orderInfo;
}
/**
* @author chenniang
* @DataTime: 2020-11-11 09:25
* @功能说明:餐饮订单打印
*/
public function restaurantOrder($id){
$order_model = new \app\restaurant\model\Order();
//订单信息
$order = $order_model->dataInfo(['id'=>$id]);
$table_model = new Table();
$table_title = $table_model->where(['id'=>$order['table_id']])->value('title');
$brs = "<BR>";
$orderInfo = '<CB>'.'餐饮订单小票'.'</CB><BR>';
$orderInfo .= '订单号:'.$order['order_code'].$brs;
$orderInfo .= '人数:'.$order['user_num'].$brs;
$orderInfo .= '桌号:'.$table_title.$brs;
$orderInfo .= '下单时间:'.date('Y-m-d H:i:s',$order['create_time']).$brs;
$orderInfo .= '--------------------------------'.$brs;
$orderInfo .= '商品/规格/数量/价格'.$brs;
$orderInfo .= '--------------------------------'.$brs;
foreach ($order['order_goods'] as $v) {
$v['goods_name'] = mb_convert_encoding($v['goods_name'], "UTF-8", "auto");
$orderInfo .= $v['goods_name'].$brs;
$orderInfo .= '【'.$v['spe_name'].'】'.$brs;
$orderInfo .= ' X'.$v['goods_num'].' '.round($v['pay_price'],2).'元'.$brs;
$orderInfo .= ''.$brs;
$orderInfo .= ''.$brs;
}
$orderInfo .= '--------------------------------'.$brs;
$orderInfo .= '原价:'.$order['init_price'].$brs;
$orderInfo .= '优惠:'.round($order['init_price']-$order['pay_price'],2).$brs;
$orderInfo .= '实付:'.$order['pay_price'].$brs;
$user_model = new User();
$user = $user_model->dataInfo(['id'=>$order['user_id']]);
$orderInfo .= $user['nickName'].' '.$user['phone'].$brs;
$orderInfo .= '备注:'.$order['text'].$brs;
return $orderInfo;
}
/**
* @author chenniang
* @DataTime: 2020-11-11 09:25
* @功能说明:赛车订单打印
*/
public function carOrder($id){
$order_model = new Order();
//订单信息
$order = $order_model->dataInfo(['id'=>$id]);
$brs = "<BR>";
$orderInfo = '<CB>'.'赛车订单小票'.'</CB><BR>';
$orderInfo .= '订单号:'.$order['order_code'].$brs;
$orderInfo .= '下单时间:'.date('Y-m-d H:i:s',$order['create_time']).$brs;
$orderInfo .= '--------------------------------'.$brs;
$orderInfo .= '商品/数量/价格'.$brs;
$orderInfo .= '--------------------------------'.$brs;
foreach ($order['order_goods'] as $v) {
$v['goods_name'] = mb_convert_encoding($v['goods_name'], "UTF-8", "auto");
$orderInfo .= $v['goods_name'].$brs;
$orderInfo .= ' X'.$v['num'].' '.round($v['pay_price'],2).'元'.$brs;
$orderInfo .= ''.$brs;
$orderInfo .= ''.$brs;
}
$orderInfo .= '--------------------------------'.$brs;
$orderInfo .= '原价:'.$order['init_price'].$brs;
$orderInfo .= '优惠:'.round($order['init_price']-$order['pay_price'],2).$brs;
$orderInfo .= '实付:'.$order['pay_price'].$brs;
$user_model = new User();
$user = $user_model->dataInfo(['id'=>$order['user_id']]);
$orderInfo .= $user['nickName'].' '.$user['phone'].$brs;
$orderInfo .= '备注:'.$order['text'].$brs;
return $orderInfo;
}
}

View File

@@ -0,0 +1,795 @@
<?php
namespace app\massage\model;
use app\admin\model\ShopOrderRefund;
use app\BaseModel;
use think\facade\Db;
class RefundOrder extends BaseModel
{
//定义表名
protected $name = 'massage_service_refund_order';
protected $append = [
'order_goods',
'all_goods_num',
'hx_user_text'
];
/**
* @author chenniang
* @DataTime: 2021-09-23 16:52
* @功能说明:
*/
public function getHxUserText($value,$data){
if(!empty($data['hx_user'])){
$user_model = new User();
$nickName = $user_model->where(['id'=>$data['user_id']])->value('nickName');
return $nickName;
}
}
/**
* @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 RefundOrderGoods();
$dis = [
'refund_id' => $data['id']
];
$num = $order_goods_model->where($dis)->sum('num');
return $num;
}
}
/**
* @author chenniang
* @DataTime: 2021-03-17 17:16
* @功能说明:收货信息
*/
public function getOrderGoodsAttr($value,$data){
if(!empty($data['id'])){
$goods_model = new RefundOrderGoods();
$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('massage_service_refund_order_goods c','a.id = c.refund_id')
->join('shequshop_car_order d','a.order_id = d.id')
->where($dis)
->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})
->field('a.*,d.order_code as pay_order_code,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('massage_service_refund_order_goods c','a.id = c.refund_id','left')
->join('shequshop_car_order d','a.order_id = d.id','left')
->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=''){
$refund_order= $this->dataInfo(['id'=>$id]);
$order_model = new Order();
$pay_order = $order_model->dataInfo(['id'=>$refund_order['order_id']]);
if($refund_order['status']!=1){
return ['code'=>500,'msg'=>'订单状态错误'];
}
$update = [
'status' => 2,
'refund_time' => time(),
'refund_price'=> $price,
'refund_text' => $text
];
// $comm_model = new Commission();
Db::startTrans();
//分销佣金
// $comm_model->refundComm($id);
$res = $this->dataUpdate(['id'=>$refund_order['id']],$update);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'退款失败,请重试'];
}
//修改退款子订单的退款状态
$order_refund_goods = new RefundOrderGoods();
$res = $order_refund_goods->dataUpdate(['refund_id'=>$id],['status'=>2]);
if($res==0){
Db::rollback();
return ['code'=>500,'msg'=>'退款失败请重试1'.$res];
}
$order_update = [];
// if($refund_order['apply_price']>0){
// //服务费占总退款的比例
// $ser_bin = $refund_order['service_price']/$refund_order['apply_price'];
// //扣除退款后的服务费
// $coach_price = $pay_order['true_service_price'] - $price*$ser_bin;
//
// $coach_price = $coach_price>0?round($coach_price,2):0;
//
// $order_update = [
//
//
// 'true_service_price'=> $coach_price,
//
//
// ];
// }
//查看货是否退完了
$refund_success = $this->checkRefundNum($refund_order['order_id']);
//退完了 就修改订单状态
if($refund_success==1){
$order_update['pay_type'] = -1;
if(!empty($pay_order['pay_type'])&&$pay_order['pay_type']<=3){
//退换优惠券
$coupon_model = new CouponRecord();
$coupon_model->couponRefund($pay_order['id']);
}
}
if(!empty($order_update)){
$res = $order_model->dataUpdate(['id'=>$refund_order['order_id']],$order_update);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'退款失败请重试2'];
}
}
//退款
if($price>0){
$res = $this->refundCash($payConfig,$pay_order,$price,$id);
if(!empty($res['code'])){
Db::rollback();
return ['code'=>500,'msg'=>$res['msg']];
}
if($res!=true){
Db::rollback();
return ['code'=>500,'msg'=>'退款失败请重试2'];
}
}
Db::commit();
return true;
}
/**
* @param $payConfig
* @param $pay_order
* @param $price
* @param int $refund_id
* @功能说明:退钱
* @author chenniang
* @DataTime: 2021-07-12 20:31
*/
public function refundCash($payConfig,$pay_order,$price,$refund_id=0){
$order_model = new Order();
if(empty($pay_order['balance'])){
//微信退款
$response = orderRefundApi($payConfig,$pay_order['pay_price'],$price,$pay_order['transaction_id']);
//如果退款成功修改一下状态
if ( isset( $response[ 'return_code' ] ) && isset( $response[ 'result_code' ] ) && $response[ 'return_code' ] == 'SUCCESS' && $response[ 'result_code' ] == 'SUCCESS' ) {
$response['out_refund_no'] = !empty($response['out_refund_no'])?$response['out_refund_no']:$pay_order['order_code'];
if(!empty($refund_id)){
$this->dataUpdate(['id'=>$refund_id],['out_refund_no'=>$response['out_refund_no']]);
}else{
$order_model->dataUpdate(['id'=>$pay_order['id']],['coach_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];
}
}else{
$user_model = new User();
$water_model = new BalanceWater();
$user = $user_model->dataInfo(['id'=>$pay_order['user_id']]);
//修改用户余额
$res = $user_model->dataUpdate(['id'=>$pay_order['user_id']],['balance'=>$price+$user['balance']]);
if($res==0){
return false;
}
//添加余额流水
$insert = [
'uniacid' => $pay_order['uniacid'],
'user_id' => $pay_order['user_id'],
'order_id'=> $pay_order['id'],
'price' => $price,
'add' => 1,
'type' => 2,
'before_balance' => $user['balance'],
'after_balance' => $price+$user['balance'],
];
$res = $water_model->dataAdd($insert);
if($res==0){
return false;
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-03-18 10:29
* @功能说明:检查改订单款退完了没
*/
public function checkRefundNum($order_id){
$order_goods_model = new OrderGoods();
$order_refund_goods_model = new RefundOrderGoods();
$order_model = new Order();
$dis = [
'order_id' => $order_id
];
$goods_num = $order_goods_model->where($dis)->sum('num');
$dis['status'] = 2;
$refund_num= $order_refund_goods_model->where($dis)->sum('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 OrderGoods();
$refund_price = 0;
Db::startTrans();
$list = $input['list'];
foreach ($list as $k=>$value){
if(!empty($value['id'])){
$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['true_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]['goods_price'] = $order_goods['goods_price'];
$list[$k]['circle'] = $order_goods['circle'];
$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'=>'申请失败'];
}
}
}
$car_price = 0;
if($refund_price<=0){
// Db::rollback();
//
// return ['code'=>500,'msg'=>'退款金额至少为0.01元'];
}
$insert = [
'uniacid' => $order['uniacid'],
'user_id' => $order['user_id'],
'total_circle' => $order['total_circle'],
'order_code' => orderCode(),
'apply_price'=> round($refund_price,2),
'service_price'=> $refund_price,
'order_id' => $order['id'],
'text' => $input['text'],
'car_price' => $car_price,
'imgs' => !empty($input['imgs'])?implode(',',$input['imgs']):'',
'balance' => !empty($order['balance'])?$refund_price:0,
];
$res = $this->dataAdd($insert);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'申请失败'];
}
$refund_id = $this->getLastInsID();
$refund_goods_model = new RefundOrderGoods();
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'],
'num' => $value['num'],
'goods_price' => $value['goods_price'],
'circle' => $value['circle'],
'status' => 1,
];
$res = $refund_goods_model->dataAdd($insert);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'申请失败'];
}
}
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('massage_service_refund_order_goods b','a.id = b.refund_id')
->where($dis)
->group('b.order_goods_id')
->sum('b.num');
return $num;
}
/**
* @author chenniang
* @DataTime: 2021-04-12 12:04
* @功能说明:拒绝退款
*/
public function noPassRefund($refund_id){
$dis = [
'id' => $refund_id
];
$refund_order = $this->dataInfo($dis);
if($refund_order['status']!=1){
return ['code'=>500,'msg'=>'退款状态错误'];
}
$update = [
'status' => 3,
'refund_time' => time()
];
Db::startTrans();
$res = $this->dataUpdate($dis,$update);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'退款失败,请重试'];
}
//修改退款子订单的退款状态
$order_refund_goods = new RefundOrderGoods();
$res = $order_refund_goods->dataUpdate(['refund_id'=>$refund_id],['status'=>3]);
if($res!=1){
Db::rollback();
return ['code'=>500,'msg'=>'退款失败,请重试'];
}
Db::commit();
return true;
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class RefundOrderGoods extends BaseModel
{
//定义表名
protected $name = 'massage_service_refund_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('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():[];
}
}

View File

@@ -0,0 +1,185 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class SynMember extends BaseModel
{
//定义表名
protected $name = 'longbing_card_v2_restaurant_syn_member';
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page=10){
$data = $this->where($dis)->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-03-18 14:33
* @功能说明:
*/
public function datePrice($date,$uniacid,$cap_id,$end_time='',$type=1){
$end_time = !empty($end_time)?$end_time:$date+86399;
$dis = [];
$dis[] = ['status','=',2];
$dis[] = ['create_time','between',"$date,$end_time"];
$dis[] = ['uniacid',"=",$uniacid];
if(!empty($cap_id)){
$dis[] = ['cap_id','=',$cap_id];
}
if($type==1){
$price = $this->where($dis)->sum('true_cash');
return round($price,2);
}else{
$count = $this->where($dis)->count();
return $count;
}
}
/**
* @author chenniang
* @DataTime: 2021-03-18 16:06
* @功能说明:
*/
public function adminList($dis,$page=10){
$data = $this->alias('a')
->join('massage_service_coach_list b','a.coach_id = b.id')
->where($dis)
->field('a.*,b.coach_name')
->group('a.id')
->order('a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-03-30 14:36
* @功能说明:团长提现
*/
public function capCash($cap_id,$status=2,$type=0){
$dis = [
'coach_id' => $cap_id,
'status' => $status
];
if(!empty($type)){
$dis['type'] = $type;
}
$price = $this->where($dis)->sum('apply_price');
return round($price,2);
}
/**
* @author chenniang
* @DataTime: 2021-03-30 14:36
* @功能说明:团长提现
*/
public function capCashCount($cap_id,$status=2){
$dis = [
'cap_id' => $cap_id,
'status' => $status
];
$count = $this->where($dis)->count();
return $count;
}
}

553
app/massage/model/User.php Normal file
View File

@@ -0,0 +1,553 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use app\member\model\Integral;
use app\member\model\Level;
use app\member\model\Log;
use app\member\model\Rights;
use longbingcore\wxcore\PospalApi;
use think\facade\Db;
class User extends BaseModel
{
//定义表名
protected $name = 'massage_service_user_list';
/**
* @author chenniang
* @DataTime: 2021-08-29 21:18
* @功能说明:余额
*/
public function getBalanceAttr($value,$data){
if(isset($value)&&isset($data['pal_balance'])){
return round($value+$data['pal_balance'],2);
}
}
/**
* @author chenniang
* @DataTime: 2021-10-27 14:49
* @功能说明:积分
*/
public function getIntegralAttr($value,$data){
if(isset($value)&&isset($data['pal_point'])){
return $value+$data['pal_point'];
}
}
/**
* @author chenniang
* @DataTime: 2021-08-29 21:18
* @功能说明:
*/
public function getCashAttr($value,$data){
if(isset($value)){
return round($value,2);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
$data['status'] = 1;
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page,$mapor=[]){
$data = $this->where($dis)->where(function ($query) use ($mapor){
$query->whereOr($mapor);
})->order('id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2020-10-27 15:42
* @功能说明:订单自提码
*/
public function orderQr($input,$uniacid){
$data = longbingCreateWxCode($uniacid,$input,$input['page']);
$data = transImagesOne($data ,['qr_path'] ,$uniacid);
$qr = $data['qr_path'];
return $qr;
}
/**
* @author chenniang
* @DataTime: 2021-10-27 15:14
* @功能说明:向银豹同步积分和余额
*/
public function synBalanceAndPoint($user){
if(empty($user['customer_uid'])){
return false;
}
//余额
$balance = $this->where(['id'=>$user['id']])->value('balance');
//积分
$integral= $this->where(['id'=>$user['id']])->value('integral');
if($balance<=0||$integral<=0){
return false;
}
$data = [
1 => $balance,
2 => $integral
];
$log = new Log();
$api = new PospalApi();
Db::startTrans();
$res = $this->dataUpdate(['id'=>$user['id']],['balance'=>0,'integral'=>0]);
if($res==0){
Db::rollback();
return ['code'=>500,'msg'=>'同步失败'];
}
//增加日志
foreach ($data as $k=>$v){
if(!empty($v)){
$insert = [
'uniacid' => $user['uniacid'],
'user_id' => $user['id'],
'customer_uid' => $user['customer_uid'],
'type' => $k,
'value' => $v,
];
$log->dataAdd($insert);
}
}
//修改银豹的积分余额
$res = $api->updateMemberCash($user['customer_uid'],$balance,$integral);
if($res['status']){
Db::rollback();
return ['code'=>500,'msg'=>$res['messages'][0]];
}
Db::commit();
return true;
}
/**
* @author chenniang
* @DataTime: 2021-11-08 13:51
* @功能说明:同步会员到本地
*/
public function synMemberList($uniacid=1,$update=0){
$key = 'syn_member';
$lock = getCache($key,$uniacid);
setCache($key,1,60,$uniacid);
if(!empty($lock)&&$update==0){
return false;
}
$api_model = new PospalApi();
$member_model = new SynMember();
$check = 1;
$post_data = [];
$member_model->where(['uniacid'=>$uniacid])->delete();
while ($check==1){
$data = $api_model->getMemberList($post_data);
if($data['status']!='success'){
return [];
}
$pageSize = $data['data']['pageSize'];
$count = count($data['data']['result']);
//可能有第二页
if($count>=$pageSize){
$post_data = $data['postBackParameter'];
}else{
$check = 0;
}
if(!empty($data['data']['result'])){
foreach ($data['data']['result'] as $k=>$v){
$insert[$k] = [
'uid' => $v['customerUid'],
'member_name' => $v['categoryName'],
'number' => $v['number'],
'name' => $v['name'],
'phone' => $v['phone'],
'discount' => $v['discount'],
'balance' => $v['balance'],
'point' => $v['point'],
];
}
$member_model->saveAll($insert);
}
}
return true;
}
/**
* @author chenniang
* @DataTime: 2021-11-08 16:46
* @功能说明:同步会员余额积分
*/
public function synMemberCash($uniacid,$user_id){
//查询所有
$this->synMemberList($uniacid,1);
$member_model = new SynMember();
$dis = [
'uid' => $user_id
];
$data = $member_model->dataInfo($dis);
if(empty($data)){
return ['code'=>500,'msg'=>'请先绑定会员'];
}
if(empty($data['balance'])&&empty($data['point'])){
return ['code'=>500,'msg'=>'你暂无可同步的余额和积分'];
}
$api_model = new PospalApi();
Db::startTrans();
//扣除银豹平台的余额积分
$res = $api_model->updateMemberCash($user_id,$data['balance']*-1,$data['point']*-1);
if($res['status']!='success'){
Db::rollback();
return ['code'=>500,'msg'=>$res['messages'][0]];
}
$res = $member_model->dataUpdate($dis,['balance'=>0,'point'=>0]);
if($res==0){
Db::rollback();
return ['code'=>500,'msg'=>'同步失败'];
}
//给用户加余额积分
$user_model = new User();
$user = $user_model->dataInfo(['customer_uid'=>$user_id]);
$update = [
'balance' => $user['balance']+$data['balance'],
];
$res = $user_model->dataUpdate(['customer_uid'=>$user_id],$update);
if($res==0){
Db::rollback();
return ['code'=>500,'msg'=>'同步失败'];
}
//增加余额日志
if(!empty($data['balance'])){
$insert = [
'uniacid' => $uniacid,
'user_id' => $user['id'],
'type' => 5,
'add' => 1,
'price' => $data['balance'],
'before_balance' => $user['balance'],
'after_balance' => $user['balance']+$data['balance']
];
$water_model = new BalanceWater();
$water_model->dataAdd($insert);
}
//增加积分日志
if(!empty($data['point'])){
$i_model = new Integral();
$i_model->integralUserAdd($user['id'],$data['point'],$uniacid,2,7);
}
Db::commit();
return true;
}
/**
* @author chenniang
* @DataTime: 2021-10-27 16:08
* @功能说明:初次同步会员信息
*/
public function getMemberInfoOne($user,$member_code){
// if(!empty($user['customer_uid'])){
//
// return ['code'=>500,'msg'=>'你已经同步过了'];
// }
Db::startTrans();
$member_model = new SynMember();
$member_model->where(['user_id'=>$user['id']])->update(['user_id'=>0]);
$member = $member_model->dataInfo(['uid'=>$member_code]);
if(empty($member)){
Db::rollback();
return ['code'=>500,'msg'=>'未找到会员'];
}
if(!empty($member['user_id'])){
Db::rollback();
return ['code'=>500,'msg'=>'该会员卡正在被别人使用'];
}
$member_model->where(['uid'=>$member_code])->update(['user_id'=>$user['id']]);
$level_model = new Level();
//会员等级
$level = $level_model->levelInfo(['title'=>$member['member_name']]);
$update = [
'member_id' => $member['number'],
'customer_uid' => $member['uid'],
'member_level' => !empty($level)?$level['id']:0,
];
$res = $this->dataUpdate(['id'=>$user['id']],$update);
//给会员权益
if(!empty($level['id'])){
$rights_model = new Rights();
$rights_model->giveRights($level['id'],$user['id']);
}
Db::commit();
return $res;
}
/**
* @author chenniang
* @DataTime: 2021-10-27 16:24
* @功能说明:同步会员 修改积分余额
*/
public function getMemberCashAndPoint($user){
if(empty($user['customer_uid'])){
return false;
}
$api = new PospalApi();
//根据会员号获取会员信息
$member = $api->getMemberCode($user['customer_uid']);
if(empty($member['data'])){
return false;
}
$update = [
'pal_balance' => $member['data']['balance'],
'pal_point' => $member['data']['point'],
];
$res = $this->dataUpdate(['id'=>$user['id']],$update);
return $res;
}
/**
* @author chenniang
* @DataTime: 2021-10-27 16:40
* @功能说明:向银豹同步会员信息 然后银豹再向本地同步会员
*/
public function synMember($user){
//向银豹同步
$this->synBalanceAndPoint($user);
//银豹向本地同步
$this->getMemberCashAndPoint($user);
return true;
}
}

View File

@@ -0,0 +1,206 @@
<?php
namespace app\massage\model;
use app\BaseModel;
use think\facade\Db;
class Wallet extends BaseModel
{
//定义表名
protected $name = 'lbfarm_farmer_wallet';
protected $append = [
'service_cash'
];
/**
* @author chenniang
* @DataTime: 2021-04-09 09:28
* @功能说明:手续费
*/
public function getServiceCashAttr($value,$data){
if(isset($data['pay_price'])&&isset($data['true_price'])){
return round($data['pay_price']-$data['true_price'],2);
}
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:04
* @功能说明:添加
*/
public function dataAdd($data){
$data['create_time'] = time();
$res = $this->insert($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:05
* @功能说明:编辑
*/
public function dataUpdate($dis,$data){
$res = $this->where($dis)->update($data);
return $res;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:06
* @功能说明:列表
*/
public function dataList($dis,$page=10){
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2020-09-29 11:43
* @功能说明:
*/
public function dataInfo($dis){
$data = $this->where($dis)->find();
return !empty($data)?$data->toArray():[];
}
/**
* @author chenniang
* @DataTime: 2021-03-18 14:33
* @功能说明:
*/
public function datePrice($date,$uniacid,$cap_id,$end_time='',$type=1){
$end_time = !empty($end_time)?$end_time:$date+86399;
$dis = [];
$dis[] = ['status','=',2];
$dis[] = ['create_time','between',"$date,$end_time"];
$dis[] = ['uniacid',"=",$uniacid];
if(!empty($cap_id)){
$dis[] = ['cap_id','=',$cap_id];
}
if($type==1){
$price = $this->where($dis)->sum('true_cash');
return round($price,2);
}else{
$count = $this->where($dis)->count();
return $count;
}
}
/**
* @author chenniang
* @DataTime: 2021-03-18 16:06
* @功能说明:
*/
public function adminList($dis,$page=10){
$data = $this->alias('a')
->join('massage_service_coach_list b','a.coach_id = b.id')
->where($dis)
->field('a.*,b.coach_name')
->group('a.id')
->order('a.id desc')
->paginate($page)
->toArray();
return $data;
}
/**
* @author chenniang
* @DataTime: 2021-03-30 14:36
* @功能说明:团长提现
*/
public function capCash($cap_id,$status=2,$type=0){
$dis = [
'coach_id' => $cap_id,
'status' => $status
];
if(!empty($type)){
$dis['type'] = $type;
}
$price = $this->where($dis)->sum('apply_price');
return round($price,2);
}
/**
* @author chenniang
* @DataTime: 2021-03-30 14:36
* @功能说明:团长提现
*/
public function capCashCount($cap_id,$status=2){
$dis = [
'cap_id' => $cap_id,
'status' => $status
];
$count = $this->where($dis)->count();
return $count;
}
}