| | |
| | | |
| | | use app\api\controller\Controller; |
| | | use app\api\model\plus\business\Saving as SavingModel; |
| | | use app\api\model\plus\business\Business as BusinessModel; |
| | | |
| | | class Saving extends Controller |
| | | { |
| | |
| | | public function getList() |
| | | { |
| | | $model = new SavingModel(); |
| | | return $this->renderSuccess('',$model->getLists()); |
| | | $params=$this->request->param(); |
| | | return $this->renderSuccess('',$model->lists($params)); |
| | | } |
| | | |
| | | /** |
| | | * 添加记录 |
| | | */ |
| | | public function add(){ |
| | | $param=request()->param(); |
| | | $user=$this->getUser(); |
| | | $business=(new BusinessModel())->detail($param['business_card_id']); |
| | | $param['user_id']=$user['user_id']; |
| | | $param['affiliation_id']=$business['user_id']; |
| | | if($param['user_id']==$param['affiliation_id']){ |
| | | return $this->renderSuccess(''); |
| | | } |
| | | $model=new SavingModel(); |
| | | if($model->where(['type'=>$param['type'],'user_id'=>$param['user_id'],'affiliation_id'=>$param['affiliation_id'],'business_card_id'=>$param['business_card_id']])->find()){ |
| | | return $this->renderSuccess(''); |
| | | } |
| | | if((new SavingModel())->add($param)){ |
| | | return $this->renderSuccess(''); |
| | | } |
| | | return $this->renderError(); |
| | | } |
| | | |
| | | /** |
| | | * 删除记录 |
| | | */ |
| | | public function delete(){ |
| | | $param=request()->param(); |
| | | $user=$this->getUser(); |
| | | if((new SavingModel())->where(['id'=>$param['id'],'user_id'=>$user['user_id']])->delete()){ |
| | | return $this->renderSuccess('删除成功'); |
| | | } |
| | | return $this->renderError('删除失败'); |
| | | } |
| | | |
| | | /** |
| | | * 检查是否已保存 |
| | | */ |
| | | public function checkSaved(){ |
| | | $param=request()->param(); |
| | | $user=$this->getUser(); |
| | | $result=(new SavingModel())->where(['business_card_id'=>$param['business_card_id'],'user_id'=>$user['user_id'],'type'=>20])->find(); |
| | | return $this->renderSuccess(['isSaved'=>!!$result]); |
| | | } |
| | | } |