OrderModel.php 2.5 KB

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