初始化项目
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Card as CardModel;
|
||||
|
||||
/**
|
||||
* 充值卡模型
|
||||
* Class Card
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Card extends CardModel
|
||||
{
|
||||
/**
|
||||
* 获取充值卡列表
|
||||
* @param array $data
|
||||
* @return \think\Paginator
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getList($data = [])
|
||||
{
|
||||
return $this->with('user')
|
||||
->order(['create_time' => 'desc'])
|
||||
->where($data)
|
||||
->paginate(18);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param $data
|
||||
* @param array $user
|
||||
* @return bool|false|int
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add($data, $user = [])
|
||||
{
|
||||
$this->startTrans();
|
||||
try {
|
||||
if(isset($data['card_number'])){
|
||||
$data['store_user_id'] = $user['store_user_id'];
|
||||
$data['store_id'] = self::$storeId;
|
||||
$this->save($data);
|
||||
}else {
|
||||
foreach ($data as &$item){
|
||||
$item['store_user_id'] = $user['store_user_id'];
|
||||
$item['store_id'] = self::$storeId;
|
||||
}
|
||||
$this->saveAll($data);
|
||||
}
|
||||
$this->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete'=>1]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user