FissionsharingModel.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class FissionsharingModel{
  16. /**
  17. *显示订单状态单位分页
  18. show_fission_page
  19. */
  20. public function show_fission_page($search){
  21. $sql = "select so.*,og.name as goods_name,m.uname,m.avatar from ".C('DB_PREFIX')."member_sharing_order as so ,".C('DB_PREFIX')."order_goods as og ,".C('DB_PREFIX')."member as m
  22. where so.order_goods_id = og.order_goods_id and so.member_id = m.member_id ";
  23. /**
  24. $sql_count = "select * from ".C('DB_PREFIX')."member_sharing_order as so ,".C('DB_PREFIX')."order_goods as og ,".C('DB_PREFIX')."member as m
  25. where so.order_goods_id = og.order_goods_id and so.member_id = m.member_id ";
  26. **/
  27. $sql_count = "select count(so.id) as count from ".C('DB_PREFIX')."member_sharing_order as so ,".C('DB_PREFIX')."order_goods as og ,".C('DB_PREFIX')."member as m
  28. where so.order_goods_id = og.order_goods_id and so.member_id = m.member_id ";
  29. /**
  30. $sql_count = "select count(f.id) as count from ".C('DB_PREFIX')."fissionbonus as f ,".C('DB_PREFIX')."member as m
  31. where f.member_id = m.member_id ";
  32. **/
  33. if(isset($search['name']) && !empty($search['name']) ){
  34. $sql.=" and m.uname like '%".$search['name']."%'";
  35. $sql_count.=" and m.uname like '%".$search['name']."%'";
  36. }
  37. $count_arr = M()->query($sql_count);
  38. $count = $count_arr[0]['count'];
  39. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  40. $show = $Page->show();// 分页显示输出
  41. $sql.=' ORDER BY so.id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  42. $list=M()->query($sql);
  43. foreach($list as $key => $val)
  44. {
  45. //child_member_id buy_name
  46. $child_info = M('member')->field('uname')->where( array('member_id' => $val['child_member_id']) )->find();
  47. $val['buy_name'] = $child_info['uname'];
  48. $list[$key] = $val;
  49. }
  50. return array(
  51. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  52. 'list'=>$list,
  53. 'page'=>$show
  54. );
  55. }
  56. /**
  57. 获取分享的链接路径
  58. type = page/goods
  59. **/
  60. public function get_sharing_type_info($member_id,$type, $goods_id = 0)
  61. {
  62. $link_info = M('fissionsharing_link')->where( array('type' => $type, 'goods_id' => $goods_id, 'member_id' => $member_id) )->find();
  63. if(empty($link_info))
  64. {
  65. $link_data = array();
  66. $link_data['type'] = $type;
  67. $link_data['goods_id'] = $goods_id;
  68. $link_data['member_id'] = $member_id;
  69. $link_data['share_one_id'] = 0;
  70. $link_data['share_two_id'] = 0;
  71. $link_data['share_three_id'] = 0;
  72. $link_data['modify_time'] = time();
  73. M('fissionsharing_link')->add($link_data);
  74. return $link_info;
  75. }else{
  76. return $link_info;
  77. }
  78. }
  79. /**
  80. 有新的分享参数
  81. is_login(),$share_rmid
  82. **/
  83. public function newmember_param_share($member_id, $share_rmid)
  84. {
  85. $share_param = base64_decode($share_rmid);
  86. $share_arr = explode('_', $share_param);
  87. $share_time = $share_arr[5];
  88. $now_time = time();
  89. $effect_time_info = M('config')->where( array('name' => 'fissionsharing_effecttime') )->find();
  90. $effect_hour = $effect_time_info['value'];
  91. $limit_time = $share_time + intval( 3600 * $effect_hour );
  92. if( $effect_hour == 0 || ( $limit_time > $now_time ) )
  93. {
  94. $new_arr = array($share_arr[2],$share_arr[3],$share_arr[4]);
  95. $is_find = false;
  96. foreach($new_arr as $key => $val)
  97. {
  98. if($val == $member_id)
  99. {
  100. $is_find = true;
  101. }
  102. if($is_find)
  103. {
  104. $val =0;
  105. }
  106. $new_arr[$key] = $val;
  107. }
  108. if( $share_arr[0] == 'page')
  109. {
  110. $share_member_one = $new_arr[0];
  111. $share_member_two = $new_arr[1];
  112. $share_member_three = $new_arr[2];
  113. $this->get_sharing_type_info($member_id,'page', 0);
  114. $save_data = array();
  115. $save_data['share_one_id'] = $share_member_one;
  116. $save_data['share_two_id'] = $share_member_two;
  117. $save_data['share_three_id'] = $share_member_three;
  118. $save_data['modify_time'] = time();
  119. M('fissionsharing_link')->where( array('member_id' => $member_id,'type' => 'page') )->save($save_data);
  120. } else if( $share_arr[0] == 'goods' ){
  121. $goods_id = $share_arr[1];
  122. $share_member_one = $new_arr[0];
  123. $share_member_two = $new_arr[1];
  124. $share_member_three = $new_arr[2];
  125. $this->get_sharing_type_info($member_id,'goods', $goods_id);
  126. $save_data = array();
  127. $save_data['share_one_id'] = $share_member_one;
  128. $save_data['share_two_id'] = $share_member_two;
  129. $save_data['share_three_id'] = $share_member_three;
  130. $save_data['modify_time'] = time();
  131. M('fissionsharing_link')->where( array('member_id' => $member_id,'goods_id' => $goods_id,'type' => 'goods') )->save($save_data);
  132. $this->get_sharing_type_info($member_id,'page', 0);
  133. $save_data = array();
  134. $save_data['share_one_id'] = $share_member_one;
  135. $save_data['share_two_id'] = $share_member_two;
  136. $save_data['share_three_id'] = $share_member_three;
  137. $save_data['modify_time'] = time();
  138. M('fissionsharing_link')->where( array('member_id' => $member_id,'type' => 'page') )->save($save_data);
  139. }
  140. }
  141. }
  142. /**
  143. 开始检测是否需要加入分享订单分佣表
  144. **/
  145. public function add_sharing_order($order_id,$goods_id,$order_goods_id,$member_id,$store_id )
  146. {
  147. //检测活动是否开启着
  148. $is_open_fissionsharing_info = M('config')->where( array('name' => 'is_open_fissionsharing') )->find();
  149. if( $is_open_fissionsharing_info['value'] == 1 )
  150. {
  151. //开始检测是否有上级分享人 fissionsharing_type 1 全站链接 2 商品链接
  152. $fissionsharing_type_info = M('config')->where( array('name' => 'fissionsharing_type') )->find();
  153. $link_info = array();
  154. if($fissionsharing_type_info['value'] == 1)
  155. {
  156. $link_info = M('fissionsharing_link')->where( array('type' => 'page', 'member_id' => $member_id) )->find();
  157. }else if($fissionsharing_type_info['value'] == 2)
  158. {
  159. $link_info = M('fissionsharing_link')->where( array('type' => 'goods','goods_id' => $goods_id, 'member_id' => $member_id) )->find();
  160. }
  161. //var_dump($order_id,$goods_id,$order_goods_id,$member_id,$store_id, $link_info);die();
  162. if(!empty($link_info))
  163. {
  164. $fissionsharing_level_info = M('config')->where( array('name' => 'fissionsharing_level') )->find();
  165. $level = $fissionsharing_level_info['value'];
  166. //检测分佣有多少
  167. $order_goods = M('order_goods')->where( array('order_goods_id' => $order_goods_id) )->find();
  168. if($level >= 1 && $link_info['share_one_id'] >0 && $order_goods['commiss_fen_one_money'] > 0)
  169. {
  170. $member_sharing_order_data = array();
  171. $member_sharing_order_data['member_id'] = $link_info['share_one_id'];
  172. $member_sharing_order_data['child_member_id'] = $member_id;
  173. $member_sharing_order_data['order_id'] = $order_id;
  174. $member_sharing_order_data['order_goods_id'] = $order_goods_id;
  175. $member_sharing_order_data['level'] = 1;
  176. $member_sharing_order_data['store_id'] = $store_id;
  177. $member_sharing_order_data['state'] = 3;
  178. $member_sharing_order_data['money'] = $order_goods['commiss_fen_one_money'];
  179. $member_sharing_order_data['addtime'] = time();
  180. M('member_sharing_order')->add($member_sharing_order_data);
  181. $this->check_account_sharing($link_info['share_one_id']);
  182. }
  183. if($level >= 2 && $link_info['share_two_id'] >0 && $order_goods['commiss_fen_two_money'] > 0)
  184. {
  185. $member_sharing_order_data = array();
  186. $member_sharing_order_data['member_id'] = $link_info['share_two_id'];
  187. $member_sharing_order_data['child_member_id'] = $member_id;
  188. $member_sharing_order_data['order_id'] = $order_id;
  189. $member_sharing_order_data['order_goods_id'] = $order_goods_id;
  190. $member_sharing_order_data['level'] = 2;
  191. $member_sharing_order_data['store_id'] = $store_id;
  192. $member_sharing_order_data['state'] = 3;
  193. $member_sharing_order_data['money'] = $order_goods['commiss_fen_two_money'];
  194. $member_sharing_order_data['addtime'] = time();
  195. M('member_sharing_order')->add($member_sharing_order_data);
  196. $this->check_account_sharing($link_info['share_two_id']);
  197. }
  198. if($level >= 3 && $link_info['share_three_id'] >0 && $order_goods['commiss_fen_three_money'] > 0)
  199. {
  200. $member_sharing_order_data = array();
  201. $member_sharing_order_data['member_id'] = $link_info['share_three_id'];
  202. $member_sharing_order_data['child_member_id'] = $member_id;
  203. $member_sharing_order_data['order_id'] = $order_id;
  204. $member_sharing_order_data['order_goods_id'] = $order_goods_id;
  205. $member_sharing_order_data['level'] = 3;
  206. $member_sharing_order_data['store_id'] = $store_id;
  207. $member_sharing_order_data['state'] = 3;
  208. $member_sharing_order_data['money'] = $order_goods['commiss_fen_three_money'];
  209. $member_sharing_order_data['addtime'] = time();
  210. M('member_sharing_order')->add($member_sharing_order_data);
  211. $this->check_account_sharing($link_info['share_three_id']);
  212. }
  213. }
  214. }
  215. }
  216. /**
  217. 只有拼团成功或者单独购买已经发货的 , 订单退款取消佣金
  218. **/
  219. public function back_order_commiss_money($order_id)
  220. {
  221. $member_commiss_order_list = M('member_sharing_order')->where( array('order_id' =>$order_id,'state' => 1 ) )->select();
  222. if(!empty($member_commiss_order_list))
  223. {
  224. foreach($member_commiss_order_list as $member_commiss_order)
  225. {
  226. //分佣订单
  227. M('member_sharing_order')->where( array('id' =>$member_commiss_order['id'] ) )->save( array('state' => 2) );
  228. M('member_sharing')->where( array('member_id' => $member_commiss_order['member_id']) )->setDec('money',$member_commiss_order['money']);
  229. }
  230. }
  231. }
  232. /**
  233. 赠送佣金订单
  234. **/
  235. public function send_order_commiss_money($order_id)
  236. {
  237. $member_commiss_order_list = M('member_sharing_order')->where( array('order_id' =>$order_id,'state' => 3 ) )->select();
  238. if(!empty($member_commiss_order_list))
  239. {
  240. foreach($member_commiss_order_list as $member_commiss_order)
  241. {
  242. $this->check_account_sharing($member_commiss_order['member_id']);
  243. //分佣订单
  244. M('member_sharing_order')->where( array('id' =>$member_commiss_order['id'] ) )->save( array('state' => 0) );
  245. // M('member_sharing')->where( array('member_id' => $member_commiss_order['member_id']) )->setInc('money',$member_commiss_order['money']);
  246. }
  247. }
  248. }
  249. /**
  250. 赠送佣金 到账户
  251. **/
  252. public function send_order_commiss_money_do($order_id)
  253. {
  254. $member_commiss_order_list = M('member_sharing_order')->where( array('order_id' =>$order_id,'state' => 0 ) )->select();
  255. if(!empty($member_commiss_order_list))
  256. {
  257. foreach($member_commiss_order_list as $member_commiss_order)
  258. {
  259. $this->check_account_sharing($member_commiss_order['member_id']);
  260. //分佣订单
  261. M('member_sharing_order')->where( array('id' =>$member_commiss_order['id'] ) )->save( array('state' => 1) );
  262. M('member_sharing')->where( array('member_id' => $member_commiss_order['member_id']) )->setInc('money',$member_commiss_order['money']);
  263. }
  264. }
  265. }
  266. /**
  267. 检测是否已经有账户
  268. **/
  269. public function check_account_sharing($member_id)
  270. {
  271. $member_sharing_info = M('member_sharing')->where( array('member_id' => $member_id) )->find();
  272. if( empty($member_sharing_info) )
  273. {
  274. $bankname = '';
  275. $bankaccount = '';
  276. $bankusername = '';
  277. $commiss_info = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  278. if( !empty($commiss_info) )
  279. {
  280. $bankname = $commiss_info['bankname'];
  281. $bankaccount = $commiss_info['bankaccount'];
  282. $bankusername = $commiss_info['bankusername'];
  283. }
  284. $member_sharing_data = array();
  285. $member_sharing_data['member_id'] = $member_id;
  286. $member_sharing_data['money'] = 0;
  287. $member_sharing_data['dongmoney'] = 0;
  288. $member_sharing_data['getmoney'] = 0;
  289. $member_sharing_data['bankname'] = $bankname;
  290. $member_sharing_data['bankaccount'] = $bankaccount;
  291. $member_sharing_data['bankusername'] = $bankusername;
  292. M('member_sharing')->add($member_sharing_data);
  293. }
  294. }
  295. }
  296. ?>