373 lines
6.9 KiB
PHP
373 lines
6.9 KiB
PHP
<?php
|
|
namespace app\member\controller;
|
|
use app\AdminRest;
|
|
use app\member\model\Coupon;
|
|
use app\member\model\Goods;
|
|
use app\member\model\Rights;
|
|
use app\member\model\RightsRelation;
|
|
use app\member\model\StoredLevel;
|
|
use app\shop\model\AdminCoupon;
|
|
use longbingcore\wxcore\PospalApi;
|
|
use longbingcore\wxcore\WxSetting;
|
|
use think\App;
|
|
use app\member\model\Level as model;
|
|
use think\facade\Db;
|
|
|
|
|
|
class AdminLevel extends AdminRest
|
|
{
|
|
|
|
protected $model;
|
|
|
|
|
|
public function __construct(App $app) {
|
|
|
|
parent::__construct($app);
|
|
|
|
$this->model = new model();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-10-26 16:48
|
|
* @功能说明:远程同步会员等级
|
|
*/
|
|
public function synLevel(){
|
|
|
|
$api = new PospalApi();
|
|
|
|
$data = $api->getMemberLevel();
|
|
|
|
if($data['status']!='success'){
|
|
|
|
$this->errorMsg($data['messages'][0]);
|
|
}
|
|
|
|
if(!empty($data['data'])){
|
|
|
|
foreach ($data['data'] as $k=> &$v){
|
|
|
|
$insert['uniacid'] = $this->_uniacid;
|
|
|
|
$insert['title'] = $v['name'];
|
|
|
|
$insert['discount']= $v['discount'];
|
|
|
|
$insert['is_point']= $v['isPoint'];
|
|
|
|
$insert['status'] = $v['enable'];
|
|
|
|
$insert['uid'] = $v['uid'];
|
|
|
|
$find = $this->model->where(['uid'=>$v['uid']])->find();
|
|
|
|
if(empty($find)){
|
|
|
|
$this->model->insert($insert);
|
|
|
|
}else{
|
|
|
|
$this->model->where(['uid'=>$v['uid']])->update($insert);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success(true);
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-15 10:49
|
|
* @功能说明:会员等级列表
|
|
*/
|
|
public function levelList(){
|
|
|
|
$rights_model = new Rights();
|
|
|
|
$rights_model->initData($this->_uniacid);
|
|
|
|
$input = $this->_param;
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $this->_uniacid,
|
|
|
|
// 'type' => $type
|
|
];
|
|
|
|
$data = $this->model->levelList($dis,$input['limit']);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-10-28 10:22
|
|
* @功能说明:会员等级下拉框
|
|
*/
|
|
public function levelSelectV2(){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $this->_uniacid,
|
|
|
|
'status' => 1
|
|
];
|
|
|
|
$data = $this->model->where($dis)->select()->toArray();
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-15 11:21
|
|
* @功能说明:会员等级详情
|
|
*/
|
|
public function levelInfo(){
|
|
|
|
// $rights_model = new Rights();
|
|
|
|
// $rights_model->initData($this->_uniacid);
|
|
|
|
$input = $this->_param;
|
|
|
|
$dis = [
|
|
|
|
'id' => $input['id']
|
|
];
|
|
|
|
$data = $this->model->levelInfo($dis);
|
|
|
|
if(empty($data)){
|
|
|
|
$this->errorMsg('数据未找到');
|
|
}
|
|
//权益模型
|
|
$rights = new RightsRelation();
|
|
//优惠券
|
|
$coupon_model= new Coupon();
|
|
|
|
$dis = [
|
|
|
|
'member_id' => $data['id']
|
|
];
|
|
//优惠券
|
|
$data['coupon'] = $coupon_model->where($dis)->select()->toArray();
|
|
|
|
$data['coupon'] = array_values($data['coupon']);
|
|
|
|
if(!empty($data['coupon'])){
|
|
|
|
$coupon_models = new \app\massage\model\Coupon();
|
|
|
|
foreach ($data['coupon'] as &$vs){
|
|
|
|
$vs['title'] = $coupon_models->where(['id'=>$vs['coupon_id']])->value('title');
|
|
}
|
|
|
|
|
|
}
|
|
// $dis['type'] = 1;
|
|
//权益
|
|
$data['rights'] = $rights->where($dis)->column('rights_id');
|
|
|
|
$data['rights'] = array_values($data['rights']);
|
|
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-15 13:24
|
|
* @功能说明:
|
|
*/
|
|
public function levelUpdate(){
|
|
|
|
$input = $this->_input;
|
|
|
|
$dis = [
|
|
|
|
'id' => $input['id']
|
|
];
|
|
|
|
$input['uniacid'] = $this->_uniacid;
|
|
|
|
$data = $this->model->levelUpdate($dis,$input);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-17 13:42
|
|
* @功能说明:会员商品
|
|
*/
|
|
public function memberGoods(){
|
|
|
|
$input = $this->_param;
|
|
// //商品
|
|
// $data['goods'] = $this->model->memberGoods($this->_uniacid,$input['id']);
|
|
// //储值
|
|
// $data['stored'] = $this->model->storedSelect($this->_uniacid,$input['id']);
|
|
//自定义权益
|
|
$data['rights'] = $this->model->memberRights($this->_uniacid,1);
|
|
//默认权益
|
|
$data['defult_rights'] = $this->model->memberRights($this->_uniacid);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-22 18:08
|
|
* @功能说明:上下架
|
|
*/
|
|
|
|
public function statusUpdate(){
|
|
|
|
$input = $this->_input;
|
|
|
|
$dis = [
|
|
|
|
'id' => $input['id']
|
|
];
|
|
|
|
$input['uniacid'] = $this->_uniacid;
|
|
|
|
$input['status'] = $input['status']==1?0:1;
|
|
|
|
Db::startTrans();
|
|
|
|
$level = $this->model->levelInfo($dis);
|
|
|
|
if($level['type']==0){
|
|
|
|
$code = $this->model->checkStatus($input['id'],$input['status']);
|
|
|
|
if($code['code']!=200){
|
|
|
|
$this->errorMsg($code['msg']);
|
|
|
|
}
|
|
}
|
|
|
|
$data = $this->model->where($dis)->update($input);
|
|
|
|
Db::commit();
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-29 09:58
|
|
* @功能说明:等级下拉框
|
|
*/
|
|
public function levelSelect(){
|
|
|
|
$dis = [
|
|
|
|
'a.uniacid' => $this->_uniacid,
|
|
|
|
'a.use_type'=> 1,
|
|
|
|
'c.status' => 1
|
|
];
|
|
|
|
$model = new Rights();
|
|
|
|
$data = $model->goodsLevelSelect($dis);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-07-31 14:31
|
|
* @功能说明:会员等级列表选择
|
|
*/
|
|
public function memberLevelSelect(){
|
|
|
|
$dis = [
|
|
|
|
'uniacid' => $this->_uniacid,
|
|
|
|
'status' => 1
|
|
|
|
];
|
|
|
|
$data = $this->model->where($dis)->order('top')->select()->toArray();
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-07 14:45
|
|
* @功能说明:会员优惠券下拉框
|
|
*/
|
|
public function memberCouponSelect(){
|
|
|
|
$input = $this->_param;
|
|
|
|
$coupon_model = new AdminCoupon();
|
|
|
|
$dis = [
|
|
|
|
'status' => 1,
|
|
|
|
'uniacid'=> $this->_uniacid,
|
|
|
|
'send_type'=>2
|
|
];
|
|
|
|
$where = [];
|
|
|
|
if(!empty($input['title'])){
|
|
|
|
$where[] = ['title','like','%'.$input['title'].'%'];
|
|
|
|
}
|
|
|
|
$data = $coupon_model->where($dis)->where($where)->order('top desc')->paginate($input['limit'])->toArray();
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|