Storebindclass.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * 店铺分类分佣比例
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 数据层模型
  14. */
  15. class Storebindclass extends BaseModel
  16. {
  17. /**
  18. * 读取列表
  19. * @access public
  20. * @author csdeshang
  21. * @param array $condition 条件
  22. * @param int $pagesize 分页
  23. * @param string $order 排序
  24. * @param string $field 字段
  25. * @return array
  26. */
  27. public function getStorebindclassList($condition, $pagesize = '', $order = '', $field = '*')
  28. {
  29. if ($pagesize) {
  30. $result = Db::name('storebindclass')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  31. $this->page_info = $result;
  32. return $result->items();
  33. } else {
  34. $result = Db::name('storebindclass')->field($field)->where($condition)->order($order)->select()->toArray();
  35. return $result;
  36. }
  37. }
  38. /**
  39. * 读取单条记录
  40. * @access public
  41. * @author csdeshang
  42. * @param type $condition 条件
  43. * @return type
  44. */
  45. public function getStorebindclassInfo($condition)
  46. {
  47. $result = Db::name('storebindclass')->where($condition)->find();
  48. return $result;
  49. }
  50. /**
  51. * 增加
  52. * @access public
  53. * @author csdeshang
  54. * @param array $data 数据
  55. * @return bool
  56. */
  57. public function addStorebindclass($data)
  58. {
  59. return Db::name('storebindclass')->insertGetId($data);
  60. }
  61. /**
  62. * 增加
  63. * @access public
  64. * @author csdeshang
  65. * @param type $data 数据
  66. * @return type
  67. */
  68. public function addStorebindclassAll($data)
  69. {
  70. return Db::name('storebindclass')->insertAll($data);
  71. }
  72. /**
  73. * 更新
  74. * @access public
  75. * @author csdeshang
  76. * @param type $update 更新数据
  77. * @param type $condition 条件
  78. * @return type
  79. */
  80. public function editStorebindclass($update, $condition)
  81. {
  82. return Db::name('storebindclass')->where($condition)->update($update);
  83. }
  84. /**
  85. * 删除
  86. * @access public
  87. * @author csdeshang
  88. * @param array $condition 条件
  89. * @return bool
  90. */
  91. public function delStorebindclass($condition)
  92. {
  93. return Db::name('storebindclass')->where($condition)->delete();
  94. }
  95. /**
  96. * 总数量
  97. * @access public
  98. * @author csdeshang
  99. * @param array $condition 条件
  100. * @return int
  101. */
  102. public function getStorebindclassCount($condition = array())
  103. {
  104. return Db::name('storebindclass')->where($condition)->count();
  105. }
  106. /**
  107. * 取得店铺下商品分类佣金比例
  108. * @access public
  109. * @author csdeshang
  110. * @param array $goods_list 商品列表
  111. * @return array
  112. */
  113. public function getStoreGcidCommisRateList($goods_list)
  114. {
  115. if (empty($goods_list) || !is_array($goods_list))
  116. return array();
  117. // 获取绑定所有类目的自营店
  118. $own_shop_ids = model('store')->getOwnShopIds(true);
  119. //定义返回数组
  120. $store_gc_id_commis_rate = array();
  121. //取得每个店铺下有哪些商品分类
  122. $store_gc_id_list = array();
  123. foreach ($goods_list as $goods) {
  124. if (!intval($goods['gc_id']))
  125. continue;
  126. if (empty($store_gc_id_list) || empty($store_gc_id_list[$goods['store_id']]) || !in_array($goods['gc_id'], $store_gc_id_list[$goods['store_id']])) {
  127. $store_gc_id_list[$goods['store_id']][] = $goods;
  128. }
  129. }
  130. if (empty($store_gc_id_list))
  131. return $store_gc_id_commis_rate;
  132. $store_bind_class_list = array();
  133. foreach ($store_gc_id_list as $store_id => $gc_id_list) {
  134. foreach ($gc_id_list as $gc_id) {
  135. $key = $gc_id['gc_id_1'] . '|' . $gc_id['gc_id_2'] . '|' . $gc_id['gc_id_3'];
  136. if (!isset($store_bind_class_list[$key])) {
  137. //如果class_1,2,3有一个字段值匹配,就有效
  138. $condition = array();
  139. $condition[] = array('store_id', '=', $store_id);
  140. $condition[] = Db::raw('(class_1=0 AND class_2=0 AND class_3=0) OR (class_1=' . $gc_id['gc_id_1'] . ' AND class_2=0 AND class_3=0) OR (class_1=' . $gc_id['gc_id_1'] . ' AND class_2=' . $gc_id['gc_id_2'] . ' AND class_3=0) OR (class_1=' . $gc_id['gc_id_1'] . ' AND class_2=' . $gc_id['gc_id_2'] . ' AND class_3=' . $gc_id['gc_id_3'] . ')');
  141. $bind_list = $this->getStorebindclassList($condition, 1, 'class_3 desc,class_2 desc,class_1 desc');
  142. if (!empty($bind_list) && is_array($bind_list)) {
  143. $store_bind_class_list[$key] = $bind_list[0];
  144. } else {
  145. $store_bind_class_list[$key] = false;
  146. }
  147. }
  148. if ($store_bind_class_list[$key]) {
  149. $store_gc_id_commis_rate[$store_id][$gc_id['gc_id']] = $store_bind_class_list[$key]['commis_rate'];
  150. }
  151. }
  152. }
  153. return $store_gc_id_commis_rate;
  154. }
  155. }