store_bind_class.model.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * 店铺分类分佣比例
  4. *
  5. *
  6. *
  7. *
  8. * by 33hao 好商城V3 www.33hao.com 开发
  9. */
  10. defined('InShopNC') or exit('Access Invalid!');
  11. class store_bind_classModel extends Model{
  12. public function __construct(){
  13. parent::__construct('store_bind_class');
  14. }
  15. /**
  16. * 读取列表
  17. * @param array $condition
  18. *
  19. */
  20. public function getStoreBindClassList($condition,$page='',$order='',$field='*'){
  21. $result = $this->table('store_bind_class')->field($field)->where($condition)->page($page)->order($order)->select();
  22. return $result;
  23. }
  24. /**
  25. * 读取单条记录
  26. * @param array $condition
  27. *
  28. */
  29. public function getStoreBindClassInfo($condition){
  30. $result = $this->where($condition)->find();
  31. return $result;
  32. }
  33. /*
  34. * 增加
  35. * @param array $param
  36. * @return bool
  37. */
  38. public function addStoreBindClass($param){
  39. return $this->insert($param);
  40. }
  41. /*
  42. * 增加
  43. * @param array $param
  44. * @return bool
  45. */
  46. public function addStoreBindClassAll($param){
  47. return $this->insertAll($param);
  48. }
  49. /*
  50. * 更新
  51. * @param array $update
  52. * @param array $condition
  53. * @return bool
  54. */
  55. public function editStoreBindClass($update, $condition){
  56. return $this->where($condition)->update($update);
  57. }
  58. /*
  59. * 删除
  60. * @param array $condition
  61. * @return bool
  62. */
  63. public function delStoreBindClass($condition){
  64. return $this->where($condition)->delete();
  65. }
  66. /**
  67. * 总数量
  68. * @param unknown $condition
  69. */
  70. public function getStoreBindClassCount($condition = array()) {
  71. return $this->where($condition)->count();
  72. }
  73. /**
  74. * 取得店铺下商品分类佣金比例
  75. * @param array $goods_list
  76. * @return array 店铺ID=>array(分类ID=>佣金比例)
  77. */
  78. public function getStoreGcidCommisRateList($goods_list) {
  79. if (empty($goods_list) || !is_array($goods_list)) return array();
  80. // 获取绑定所有类目的自营店
  81. $own_shop_ids = Model('store')->getOwnShopIds(true);
  82. //定义返回数组
  83. $store_gc_id_commis_rate = array();
  84. //取得每个店铺下有哪些商品分类
  85. $store_gc_id_list = array();
  86. foreach ($goods_list as $goods) {
  87. if (!intval($goods['gc_id'])) continue;
  88. if (!in_array($goods['gc_id'],(array)$store_gc_id_list[$goods['store_id']])) {
  89. if (in_array($goods['store_id'], $own_shop_ids)) {
  90. //平台店铺佣金为0
  91. //$store_gc_id_commis_rate[$goods['store_id']][$goods['gc_id']] = 0;
  92. } else {
  93. //$store_gc_id_list[$goods['store_id']][] = $goods['gc_id'];
  94. }
  95. //33hao
  96. $store_gc_id_list[$goods['store_id']][] = $goods['gc_id'];
  97. }
  98. }
  99. if (empty($store_gc_id_list)) return $store_gc_id_commis_rate;
  100. $condition = array();
  101. foreach ($store_gc_id_list as $store_id => $gc_id_list) {
  102. $condition['store_id'] = $store_id;
  103. $condition['class_1|class_2|class_3'] = array('in',$gc_id_list);
  104. $bind_list = $this->getStoreBindClassList($condition);
  105. //33hao
  106. if(!$bind_list)
  107. {
  108. $condition = array();
  109. $condition['store_id'] = $store_id;
  110. $condition['class_1'] = 0;
  111. $condition['class_2'] = 0;
  112. $condition['class_3'] = 0;
  113. $bind_list = $this->getStoreBindClassList($condition);
  114. }
  115. if (!empty($bind_list) && is_array($bind_list)) {
  116. foreach ($bind_list as $bind_info) {
  117. if ($bind_info['store_id'] != $store_id) continue;
  118. //如果class_1,2,3有一个字段值匹配,就有效
  119. $bind_class = array($bind_info['class_3'],$bind_info['class_2'],$bind_info['class_1']);
  120. foreach ($gc_id_list as $gc_id) {
  121. //33hao
  122. //if (in_array($gc_id,$bind_class)) {
  123. $store_gc_id_commis_rate[$store_id][$gc_id] = $bind_info['commis_rate'];
  124. //}
  125. }
  126. }
  127. }
  128. }
  129. return $store_gc_id_commis_rate;
  130. }
  131. }