Storebindclass.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * 店铺分类分佣比例
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 数据层模型
  19. */
  20. class Storebindclass extends BaseModel {
  21. /**
  22. * 读取列表
  23. * @access public
  24. * @author csdeshang
  25. * @param array $condition 条件
  26. * @param int $pagesize 分页
  27. * @param string $order 排序
  28. * @param string $field 字段
  29. * @return array
  30. */
  31. public function getStorebindclassList($condition, $pagesize = '', $order = '', $field = '*') {
  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. $result = Db::name('storebindclass')->where($condition)->find();
  50. return $result;
  51. }
  52. /**
  53. * 增加
  54. * @access public
  55. * @author csdeshang
  56. * @param array $data 数据
  57. * @return bool
  58. */
  59. public function addStorebindclass($data) {
  60. return Db::name('storebindclass')->insertGetId($data);
  61. }
  62. /**
  63. * 增加
  64. * @access public
  65. * @author csdeshang
  66. * @param type $data 数据
  67. * @return type
  68. */
  69. public function addStorebindclassAll($data) {
  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. return Db::name('storebindclass')->where($condition)->update($update);
  82. }
  83. /**
  84. * 删除
  85. * @access public
  86. * @author csdeshang
  87. * @param array $condition 条件
  88. * @return bool
  89. */
  90. public function delStorebindclass($condition) {
  91. return Db::name('storebindclass')->where($condition)->delete();
  92. }
  93. /**
  94. * 总数量
  95. * @access public
  96. * @author csdeshang
  97. * @param array $condition 条件
  98. * @return int
  99. */
  100. public function getStorebindclassCount($condition = array()) {
  101. return Db::name('storebindclass')->where($condition)->count();
  102. }
  103. /**
  104. * 取得店铺下商品分类佣金比例
  105. * @access public
  106. * @author csdeshang
  107. * @param array $goods_list 商品列表
  108. * @return array
  109. */
  110. public function getStoreGcidCommisRateList($goods_list) {
  111. if (empty($goods_list) || !is_array($goods_list))
  112. return array();
  113. // 获取绑定所有类目的自营店
  114. $own_shop_ids = model('store')->getOwnShopIds(true);
  115. //定义返回数组
  116. $store_gc_id_commis_rate = array();
  117. //取得每个店铺下有哪些商品分类
  118. $store_gc_id_list = array();
  119. foreach ($goods_list as $goods) {
  120. if (!intval($goods['gc_id']))
  121. continue;
  122. 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']])) {
  123. $store_gc_id_list[$goods['store_id']][] = $goods;
  124. }
  125. }
  126. if (empty($store_gc_id_list))
  127. return $store_gc_id_commis_rate;
  128. $store_bind_class_list=array();
  129. foreach ($store_gc_id_list as $store_id => $gc_id_list) {
  130. foreach ($gc_id_list as $gc_id) {
  131. $key=$gc_id['gc_id_1'].'|'.$gc_id['gc_id_2'].'|'.$gc_id['gc_id_3'];
  132. if(!isset($store_bind_class_list[$key])){
  133. //如果class_1,2,3有一个字段值匹配,就有效
  134. $condition = array();
  135. $condition[]=array('store_id','=',$store_id);
  136. $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'] . ')');
  137. $bind_list = $this->getStorebindclassList($condition, 1, 'class_3 desc,class_2 desc,class_1 desc');
  138. if (!empty($bind_list) && is_array($bind_list)) {
  139. $store_bind_class_list[$key]=$bind_list[0];
  140. }else{
  141. $store_bind_class_list[$key]=false;
  142. }
  143. }
  144. if ($store_bind_class_list[$key]) {
  145. $store_gc_id_commis_rate[$store_id][$gc_id['gc_id']] = $store_bind_class_list[$key]['commis_rate'];
  146. }
  147. }
  148. }
  149. return $store_gc_id_commis_rate;
  150. }
  151. }