Chain.php 5.1 KB

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