1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\index\model;
- use app\index\model\BoxModel;
- use think\Exception;
- use think\Model;
- class OrderModel extends Model{
- // 确定链接表名
- protected $name = 'order';
- public function getOne($order_sn){
- return $this->where('order_sn' , $order_sn)->find();
- }
- public function Box()
- {
- return $this->hasOne('BoxModel', 'order_sn', 'order_sn');
- }
- public function CreateOrder($params){
- try {
- $result = $this->save($params);
- if(false === $result){
- // 验证失败 输出错误信息
- return msg(-1, '', $this->getError());
- }else{
- $BoxModel = new BoxModel();
- $ret = $BoxModel->save(['order_sn' => $params['order_sn'] , 'box_status' => 2] , ['cabinet_number' => $params['cabinet_number'] , 'box_number' => $params['box_number']]);
- if($ret === false){
- return msg(-1, '', $this->getError());
- }else{
- return msg(1, '', 'success');
- }
- }
- }catch (Exception $e){
- return msg(-2, '', $e->getMessage());
- }
- }
- public function CheckCode($code){
- return $this->where('code' , $code)->find();
- }
- /**
- * 根据既定条件修改信息
- * @where $param
- * @update $param
- */
- public function editData($where,$update)
- {
- try{
- $result = $this->save($update, $where);
- if(false === $result){
- // 验证失败 输出错误信息
- return msg(-1, '', $this->getError());
- }else{
- return msg(1, '', 'success');
- }
- }catch(\Exception $e){
- return msg(-2, '', $e->getMessage());
- }
- }
- /**
- * 检查取件码
- */
- public function check_fcode($code)
- {
- $where['sc_order.code'] = $code;
- $where['BoxModel.box_status'] = 2;
- try{
- $order = $this->Box()->hasWhere($where)->find();
- if(empty($order)){
- // 验证失败 输出错误信息
- return msg(-1, '', $this->getError());
- }else{
- $data['code'] = $code;
- $data['existed'] = true;
- $data['trunk'] = $order['box_number'];
- $data['cabinet'] = $order['cabinet_number'];
- return msg(1, $data, 'success');
- }
- }catch(\Exception $e){
- return msg(-2, '', $e->getMessage());
- }
- }
- }
|