BoxModel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\index\model;
  3. use think\Model;
  4. class BoxModel extends Model {
  5. // 确定链接表名
  6. protected $name = 'box';
  7. public function Order()
  8. {
  9. return $this->hasOne('OrderModel', 'order_sn', 'order_sn')->joinType('LEFT');
  10. }
  11. /**
  12. * 根据柜号箱号获取箱子信息
  13. * @cabinet_number $param
  14. * @box_number $param
  15. */
  16. public function getOneCabinetBox($cabinet_number,$box_number)
  17. {
  18. return $this->where(['cabinet_number' => $cabinet_number, 'box_number'=>$box_number])->find();
  19. }
  20. /**
  21. * 根据既定条件修改信息
  22. * @where $param
  23. * @update $param
  24. */
  25. public function editData($where,$update)
  26. {
  27. try{
  28. $result = $this->save($update, $where);
  29. if(false === $result){
  30. // 验证失败 输出错误信息
  31. return msg(-1, '', $this->getError());
  32. }else{
  33. return msg(1, '', 'success');
  34. }
  35. }catch(\Exception $e){
  36. return msg(-2, '', $e->getMessage());
  37. }
  38. }
  39. /**
  40. * 根据搜索条件获取箱子列表信息
  41. * @param $offset
  42. * @param $limit
  43. */
  44. public function getBoxsByWhere($where)
  45. {
  46. return $this->Order()->haswhere($where)->order('sc_box.box_number asc')->field('sc_box.*,OrderModel.enter_time')->select();
  47. }
  48. /**
  49. * 根据搜索条件获取所有的箱子数量
  50. */
  51. public function getAllCounts()
  52. {
  53. return $this->count();
  54. }
  55. }