OrderModel.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\index\model;
  3. use think\Model;
  4. use app\index\model\BoxModel;
  5. class OrderModel extends Model{
  6. // 确定链接表名
  7. protected $name = 'order';
  8. public function getOne($order_sn){
  9. return $this->where('order_sn' , $order_sn)->find();
  10. }
  11. public function Box()
  12. {
  13. return $this->hasOne('BoxModel', 'order_sn', 'order_sn');
  14. }
  15. /**
  16. * 根据既定条件修改信息
  17. * @where $param
  18. * @update $param
  19. */
  20. public function editData($where,$update)
  21. {
  22. try{
  23. $result = $this->save($update, $where);
  24. if(false === $result){
  25. // 验证失败 输出错误信息
  26. return msg(-1, '', $this->getError());
  27. }else{
  28. return msg(1, '', 'success');
  29. }
  30. }catch(\Exception $e){
  31. return msg(-2, '', $e->getMessage());
  32. }
  33. }
  34. /**
  35. * 检查取件码
  36. */
  37. public function check_fcode($code)
  38. {
  39. $where['sc_order.code'] = $code;
  40. $where['BoxModel.box_status'] = 2;
  41. try{
  42. $order = $this->Box()->hasWhere($where)->find();
  43. if(empty($order)){
  44. // 验证失败 输出错误信息
  45. return msg(-1, '', $this->getError());
  46. }else{
  47. $data['code'] = $code;
  48. $data['existed'] = true;
  49. $data['trunk'] = $order['box_number'];
  50. $data['cabinet'] = $order['cabinet_number'];
  51. return msg(1, $data, 'success');
  52. }
  53. }catch(\Exception $e){
  54. return msg(-2, '', $e->getMessage());
  55. }
  56. }
  57. }