Storebindclass.php 5.7 KB

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