Chain.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Chain extends BaseModel
  12. {
  13. const STATE1 = 1; // 开启
  14. const STATE0 = 0; // 关闭
  15. const STATE10 = 10; // 等待审核
  16. const STATE20 = 20; // 等待失败
  17. private $state = array(
  18. self::STATE0 => '关闭', self::STATE1 => '开启', self::STATE10 => '等待审核', self::STATE20 => '审核失败'
  19. );
  20. public $page_info;
  21. /**
  22. * 插入数据
  23. * @access public
  24. * @author csdeshang
  25. * @param array $data 数据
  26. * @return boolean
  27. */
  28. public function addChain($data)
  29. {
  30. return Db::name('chain')->insertGetId($data);
  31. }
  32. /**
  33. * 查询门店列表
  34. * @access public
  35. * @author csdeshang
  36. * @param array $condition 检索条件
  37. * @param int $pagesize 分页信息
  38. * @param string $order 排序
  39. * @return array
  40. */
  41. public function getChainList($condition, $pagesize = 0, $order = 'chain_id desc')
  42. {
  43. if ($pagesize) {
  44. $res = Db::name('chain')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  45. $this->page_info = $res;
  46. return $res->items();
  47. } else {
  48. return Db::name('chain')->where($condition)->order($order)->select()->toArray();
  49. }
  50. }
  51. /**
  52. * 等待审核的门店列表
  53. * @access public
  54. * @author csdeshang
  55. * @param unknown $condition 条件
  56. * @param number $pagesize 分页信息
  57. * @param string $order 排序
  58. * @return array
  59. */
  60. public function getChainWaitVerifyList($condition, $pagesize = 0, $order = 'chain_id desc')
  61. {
  62. $condition[] = array('chain_state', '=', self::STATE10);
  63. return $this->getChainList($condition, $pagesize, $order);
  64. }
  65. /**
  66. * 等待审核的门店数量
  67. * @access public
  68. * @author csdeshang
  69. * @param array $condition 条件
  70. * @param number $pagesize 分页信息
  71. * @param string $order 排序
  72. * @return int
  73. */
  74. public function getChainWaitVerifyCount($condition)
  75. {
  76. $condition[] = array('chain_state', '=', self::STATE10);
  77. return Db::name('chain')->where($condition)->count();
  78. }
  79. /**
  80. * 开启中物流门店列表
  81. * @access public
  82. * @author csdeshang
  83. * @param array $condition 检索条件
  84. * @param number $pagesize 分页信息
  85. * @param string $order 排序
  86. * @return array
  87. */
  88. public function getChainOpenList($condition, $pagesize = 0, $order = 'chain_id desc')
  89. {
  90. $condition[] = array('chain_state', '=', self::STATE1);
  91. return $this->getChainList($condition, $pagesize, $order);
  92. }
  93. /**
  94. * 取得门店详细信息
  95. * @access public
  96. * @author csdeshang
  97. * @param array $condition 检索条件
  98. * @param string $field 字段
  99. * @return array
  100. */
  101. public function getChainInfo($condition, $field = '*')
  102. {
  103. return Db::name('chain')->where($condition)->field($field)->find();
  104. }
  105. /**
  106. * 取得开启中物流门店信息
  107. * @access public
  108. * @author csdeshang
  109. * @param array $condition 条件
  110. * @param string $field 字段
  111. * @return array
  112. */
  113. public function getChainOpenInfo($condition, $field = '*')
  114. {
  115. $condition[] = array('chain_state', '=', self::STATE1);
  116. return Db::name('chain')->where($condition)->field($field)->find();
  117. }
  118. /**
  119. * 取得开启中物流门店信息
  120. * @access public
  121. * @author csdeshang
  122. * @param array $condition 条件
  123. * @param string $field 字段
  124. * @return array
  125. */
  126. public function getChainFailInfo($condition, $field = '*')
  127. {
  128. $condition[] = array('chain_state', '=', self::STATE20);
  129. return Db::name('chain')->where($condition)->field($field)->find();
  130. }
  131. /**
  132. * 门店信息
  133. * @access public
  134. * @author csdeshang
  135. * @param array $update 更新数据
  136. * @param array $condition 条件
  137. * @return bool
  138. */
  139. public function editChain($update, $condition)
  140. {
  141. return Db::name('chain')->where($condition)->update($update);
  142. }
  143. /**
  144. * 删除门店
  145. * @access public
  146. * @author csdeshang
  147. * @param int $condition 记录ID
  148. * @return bool
  149. */
  150. public function delChain($condition)
  151. {
  152. return Db::name('chain')->where($condition)->delete();
  153. }
  154. /**
  155. * @access public
  156. * @author csdeshang
  157. * 返回状态数组
  158. * @return array
  159. */
  160. public function getChainState()
  161. {
  162. return $this->state;
  163. }
  164. }