OrderModel.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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] , ['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'] = 1;
  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. /**
  81. * 根据搜索条件获取箱子列表信息
  82. * @param $offset
  83. * @param $limit
  84. */
  85. public function getOrdersByWhere( $offset, $limit)
  86. {
  87. return $this->limit($offset, $limit)->order('id desc')->select();
  88. }
  89. /**
  90. * 根据搜索条件获取所有的箱子数量
  91. */
  92. public function getAllCounts()
  93. {
  94. return $this->count();
  95. }
  96. }