OrderModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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'] , 'fetch_code' => $params['code'] , 'box_status' => 1] ,
  25. ['cabinet_number' => $params['cabinet_number'] , 'box_number' => $params['box_number']]);
  26. if($ret === false){
  27. return msg(-1, '', $this->getError());
  28. }else{
  29. return msg(1, '', 'success');
  30. }
  31. }
  32. }catch (Exception $e){
  33. return msg(-2, '', $e->getMessage());
  34. }
  35. }
  36. /**
  37. * 根据既定条件修改信息
  38. * @where $param
  39. * @update $param
  40. */
  41. public function editData($where,$update)
  42. {
  43. try{
  44. $result = $this->save($update, $where);
  45. if(false === $result){
  46. // 验证失败 输出错误信息
  47. return msg(-1, '', $this->getError());
  48. }else{
  49. return msg(1, '', 'success');
  50. }
  51. }catch(\Exception $e){
  52. return msg(-2, '', $e->getMessage());
  53. }
  54. }
  55. /**
  56. * 检查取件码
  57. */
  58. public function check_fcode($code)
  59. {
  60. $where['sc_order.code'] = $code;
  61. $where['BoxModel.box_status'] = 1;
  62. try{
  63. $order = $this->Box()->hasWhere($where)->find();
  64. if(empty($order)){
  65. // 验证失败 输出错误信息
  66. return msg(-1, '', $this->getError());
  67. }else{
  68. $data['code'] = $code;
  69. $data['existed'] = true;
  70. $data['trunk'] = $order['box_number'];
  71. $data['cabinet'] = $order['cabinet_number'];
  72. return msg(1, $data, 'success');
  73. }
  74. }catch(\Exception $e){
  75. return msg(-2, '', $e->getMessage());
  76. }
  77. }
  78. public function checkOrder($order_sn){
  79. return $this->where(['order_sn' => $order_sn])->find();
  80. }
  81. /**
  82. * 根据搜索条件获取箱子列表信息
  83. * @param $offset
  84. * @param $limit
  85. */
  86. public function getOrdersByWhere($where, $offset, $limit)
  87. {
  88. return $this->where($where)->limit($offset, $limit)->order('id desc')->select();
  89. }
  90. /**
  91. * 根据搜索条件获取所有的箱子数量
  92. */
  93. public function getAllCounts($where)
  94. {
  95. return $this->where($where)->count();
  96. }
  97. }