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