1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\index\model;
- use think\Model;
- use app\index\model\BoxModel;
- use think\exception\PDOException;
- class CabinetModel extends Model{
- // 确定链接表名
- protected $name = 'cabinet';
- /**
- * 插入柜子信息
- * @param $param
- */
- public function insertCabinet($url,$alias,$count,$number,$login_key)
- {
- try
- {
- $this->startTrans();
- $result = $this->save(['req_url' => $url,'alias' => $alias,'box_count' => $count,'cabinet_code' => $number,'login_key' => $login_key]);
- if(false === $result){
- $this->rollback();
- return msg(-1, '', $this->getError());
- }
- else
- {
- $cabinet_number = intval($this->id);
- $boxData = [];
- for ($i=1; $i <= $count; $i++) {
- $boxData['cabinet_number'] = $cabinet_number;
- $boxData['box_number'] = $i;
- $saveAllData[] = $boxData;
- }
- $BoxModel = new BoxModel();
- $result = $BoxModel->saveAll($saveAllData);
- if(false === $result){
- $this->rollback();
- return msg(-1, '', $this->getError());
- }else{
- $this->commit();
- return msg(1, '', '添加成功');
- }
- }
- }
- catch(PDOException $e){
- $this->rollback();
- return msg(-2, '', $e->getMessage());
- }
- }
- /**
- * 根据搜索条件获取柜子列表信息
- * @param $where
- * @param $offset
- * @param $limit
- */
- public function getCabinetsByWhere()
- {
- return $this->order('id desc')->select();
- }
- /**
- * 根据搜索条件获取所有的柜子数量
- * @param $where
- */
- public function getAllCabinets()
- {
- return $this->count();
- }
- public function DelCabinetBox($cabinet_number){
- try {
- $this->startTrans();
- $ret = $this->where('id' , $cabinet_number)->delete($cabinet_number);
- if(false === $ret){
- $this->rollback();
- return msg(-1, '', $this->getError());
- }else{
- $BoxModel = new BoxModel();
- $ret = $BoxModel->where('cabinet_number' , $cabinet_number)->delete();
- if(false === $ret){
- $this->rollback();
- return msg(-1, '', $this->getError());
- }else{
- $this->commit();
- return msg(1, '', '删除成功');
- }
- }
- }catch(PDOException $e){
- $this->rollback();
- return msg(-2, '', $e->getMessage());
- }
- }
- }
|