初始化代码
This commit is contained in:
177
app/member/model/Stored.php
Normal file
177
app/member/model/Stored.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
namespace app\member\model;
|
||||
|
||||
use app\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Stored extends BaseModel
|
||||
{
|
||||
//会员权益表
|
||||
protected $name = 'longbing_card_member_stored';
|
||||
|
||||
protected $append = [
|
||||
|
||||
'stored_type'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-11 11:07
|
||||
* @功能说明:储值卡的类型
|
||||
*/
|
||||
public function getStoredTypeAttr($value,$data){
|
||||
|
||||
if(!empty($data['id'])){
|
||||
|
||||
$stored_level_model = new StoredLevel();
|
||||
|
||||
$type = $stored_level_model->storedType($data['id']);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-09-09 10:37
|
||||
* @功能说明:列表
|
||||
*/
|
||||
public function storedList($dis,$page){
|
||||
|
||||
$data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-07-15 09:49
|
||||
* @功能说明:添加
|
||||
*/
|
||||
public function storedAdd($data){
|
||||
|
||||
$data['create_time'] = time();
|
||||
|
||||
$data['update_time'] = time();
|
||||
|
||||
$data['status'] = 1;
|
||||
|
||||
if(isset($data['coupon'])){
|
||||
|
||||
$coupon = $data['coupon'];
|
||||
|
||||
unset($data['coupon']);
|
||||
}
|
||||
|
||||
$res = $this->insert($data);
|
||||
|
||||
if(!empty($coupon)){
|
||||
|
||||
$id = $this->getLastInsID();
|
||||
|
||||
$this->updateSome($id,$coupon,$data['uniacid']);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-08-27 17:16
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function updateSome($id,$coupon,$uniacid){
|
||||
|
||||
$coupon_model = new StoredCoupon();
|
||||
|
||||
$coupon_model->where(['stored_id'=>$id])->delete();
|
||||
|
||||
if(!empty($coupon)){
|
||||
|
||||
foreach ($coupon as $value){
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'coupon_id'=> $value['coupon_id'],
|
||||
|
||||
'stored_id'=> $id,
|
||||
|
||||
'num' => $value['num']
|
||||
|
||||
];
|
||||
|
||||
$coupon_model->insert($insert);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-26 17:08
|
||||
* @功能说明:详情
|
||||
*/
|
||||
public function storedInfo($dis){
|
||||
|
||||
$data = $this->where($dis)->find();
|
||||
|
||||
return !empty($data)?$data->toArray():[];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-26 17:13
|
||||
* @功能说明:编辑
|
||||
*/
|
||||
public function storedUpdate($dis,$data){
|
||||
|
||||
$data['update_time'] = time();
|
||||
|
||||
if(isset($data['coupon'])){
|
||||
|
||||
$coupon = $data['coupon'];
|
||||
|
||||
unset($data['coupon']);
|
||||
}
|
||||
|
||||
$res = $this->where($dis)->update($data);
|
||||
|
||||
if(!empty($coupon)){
|
||||
|
||||
$id = $dis['id'];
|
||||
|
||||
$this->updateSome($id,$coupon,$data['uniacid']);
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user