SupplyModel.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 SupplyModel{
  16. public function modify_supply($data)
  17. {
  18. global $_W;
  19. global $_GPC;
  20. if($data['id'] > 0)
  21. {
  22. //update ims_
  23. $id = $data['id'];
  24. unset($data['id']);
  25. if( empty($data['login_password']) )
  26. {
  27. unset($data['login_password']);
  28. }else{
  29. $slat = mt_rand(1,9).mt_rand(1,9).mt_rand(1,9).mt_rand(1,9).mt_rand(1,9).mt_rand(1,9);
  30. $data['login_password'] = md5( $slat.$data['login_password'] );
  31. $data['login_slat'] = $slat;
  32. }
  33. M('lionfish_comshop_supply')->where( array('id' => $id ) )->save( $data );
  34. }else{
  35. //insert
  36. $slat = mt_rand(1,9).mt_rand(1,9).mt_rand(1,9).mt_rand(1,9).mt_rand(1,9).mt_rand(1,9);
  37. $data['login_password'] = md5( $slat.$data['login_password'] );
  38. $data['login_slat'] = $slat;
  39. M('lionfish_comshop_supply')->add($data);
  40. }
  41. return true;
  42. }
  43. //----begin
  44. /**
  45. 检测供应商权限的方法
  46. **/
  47. public function checksupply_pri( $action_do )
  48. {
  49. if (defined('ROLE') && ROLE == 'agenter' )
  50. {
  51. $config_data = D('Seller/Config')->get_all_config();
  52. $is_can = true;
  53. switch($action_do)
  54. {
  55. case 'grounding':
  56. if( isset($config_data['supply_can_goods_updown']) && $config_data['supply_can_goods_updown'] == 2 )
  57. {
  58. $is_can = false;
  59. }
  60. break;
  61. case 'is_index_show':
  62. if( isset($config_data['supply_can_goods_isindex']) && $config_data['supply_can_goods_isindex'] == 2 )
  63. {
  64. $is_can = false;
  65. }
  66. case 'istop':
  67. if( isset($config_data['supply_can_goods_istop']) && $config_data['supply_can_goods_istop'] == 2 )
  68. {
  69. $is_can = false;
  70. }
  71. break;
  72. }
  73. return $is_can;
  74. }else{
  75. return true;
  76. }
  77. }
  78. public function ins_supply_commiss_order($order_id,$order_goods_id, $add_money)
  79. {
  80. $add_money = 0;
  81. $order_goods_info = M('lionfish_comshop_order_goods')->field('goods_id,supply_id,total,shipping_fare,fullreduction_money,voucher_credit,packing_fare,quantity')
  82. ->where( array('order_goods_id' => $order_goods_id ) )->find();
  83. $order_info = M('lionfish_comshop_order')->field('delivery')->where( array('order_id' => $order_id ) )->find();
  84. if( empty($order_goods_info) )
  85. {
  86. return true;
  87. }else {
  88. //head_id commiss_bili
  89. $supply_info = D('Home/Front')->get_supply_info($order_goods_info['supply_id']);
  90. //...begin
  91. $head_commiss_info_list = M('lionfish_community_head_commiss_order')->field('money,add_shipping_fare')
  92. ->where( array('order_goods_id' => $order_goods_id ) )->select();
  93. $head_commiss_money = 0;
  94. if( !empty($head_commiss_info_list) )
  95. {
  96. foreach( $head_commiss_info_list as $val)
  97. {
  98. $head_commiss_money += $val['money'] - $val['add_shipping_fare'];
  99. }
  100. }
  101. //order_id
  102. $member_commiss_list = M('lionfish_comshop_member_commiss_order')->field('money')->where( array('order_goods_id' => $order_goods_id,'order_id' => $order_id) )->select();
  103. $member_commiss_money = 0;
  104. if( !empty($member_commiss_list) )
  105. {
  106. foreach( $member_commiss_list as $val)
  107. {
  108. $member_commiss_money += $val['money'];
  109. }
  110. }
  111. /**
  112. 商品 100 满减2 优惠券3 团长配送费 4 。 实付 100-2-3+4.。。那么
  113. 团长分佣: 10% *(100-2-3)+4(即配送费)
  114. 供应商得 (100-2-3)*90%
  115. **/
  116. //独立供应商
  117. //$order_goods_info['packing_fare'] 包装费 - 配送员费用
  118. $money = round( ( (100 - $supply_info['commiss_bili']) * ($order_goods_info['total'] -$order_goods_info['fullreduction_money']-$order_goods_info['voucher_credit']))/100 + $order_goods_info['packing_fare']*$order_goods_info['quantity'] ,2 ) ;
  119. $total_money = round( ($order_goods_info['total'] -$order_goods_info['fullreduction_money']-$order_goods_info['voucher_credit']) ,2 );
  120. $money = $money - $head_commiss_money - $member_commiss_money;
  121. $shipping_fare = 0;
  122. //如果是团长配送 供应商不计算 运费, 只有快递配送,才把运费算给团长
  123. //if( $order_goods_info['supply_id'] > 0 && $order_info['delivery'] != 'tuanz_send')
  124. if( $order_goods_info['supply_id'] > 0 && $order_info['delivery'] != 'tuanz_send' )
  125. {
  126. $su_info = M('lionfish_comshop_supply')->where( array('id' => $order_goods_info['supply_id'] ) )->find();
  127. if( $su_info['type'] == 1 )
  128. {
  129. $shipping_fare = $order_goods_info['shipping_fare'];
  130. $money += $shipping_fare;
  131. }
  132. //$order_goods_info['supply_id']
  133. }
  134. //end
  135. if($money <=0)
  136. {
  137. $money = 0;
  138. }
  139. //退款才能取消的
  140. $ins_data = array();
  141. $ins_data['supply_id'] = $order_goods_info['supply_id'];
  142. $ins_data['order_id'] = $order_id;
  143. $ins_data['order_goods_id'] = $order_goods_id;
  144. $ins_data['state'] = 0;
  145. $ins_data['total_money'] = $total_money;
  146. $ins_data['comunity_blili'] = $supply_info['commiss_bili'];
  147. $ins_data['member_commiss_money'] = $member_commiss_money;
  148. $ins_data['head_commiss_money'] = $head_commiss_money;
  149. $ins_data['money'] = $money;
  150. $ins_data['shipping_fare'] = $shipping_fare;
  151. $ins_data['addtime'] = time();
  152. M('lionfish_supply_commiss_order')->add( $ins_data );
  153. return true;
  154. }
  155. }
  156. public function update_supply_commission($order_id,$shipping_money){
  157. $list = M()->query("select * from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_id={$order_id} ");
  158. foreach($list as $var)
  159. {
  160. $goods_shippingmoney = $shipping_money * $var['fenbi_li'];
  161. M('lionfish_supply_commiss_order')->where( array('order_goods_id' => $var['order_goods_id'] ) )->setDec('money', $goods_shippingmoney);
  162. }
  163. }
  164. public function thirth_cancel_supply_commission($order_id,$shipping_money){
  165. $list = M()->query("select * from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_id={$order_id} ");
  166. foreach($list as $var)
  167. {
  168. $goods_shippingmoney = $shipping_money * $var['fenbi_li'];
  169. M('lionfish_supply_commiss_order')->where( array('order_goods_id' => $var['order_goods_id'] ) )->setInc('money', $goods_shippingmoney);
  170. }
  171. }
  172. public function send_supply_commission($order_id)
  173. {
  174. $list = M()->query("select * from ".C('DB_PREFIX')."lionfish_supply_commiss_order where order_id={$order_id} ");
  175. foreach($list as $commiss)
  176. {
  177. if( $commiss['state'] == 0)
  178. {
  179. //supply_id
  180. M('lionfish_supply_commiss_order')->where( array('id' => $commiss['id'] ) )->save( array('state' => 1) );
  181. $comiss_info = M('lionfish_supply_commiss')->where( array('supply_id' => $commiss['supply_id'] ) )->find();
  182. if( empty($comiss_info) )
  183. {
  184. $ins_data = array();
  185. $ins_data['supply_id'] = $commiss['supply_id'];
  186. $ins_data['money'] = 0;
  187. $ins_data['dongmoney'] = 0;
  188. $ins_data['getmoney'] = 0;
  189. M('lionfish_supply_commiss')->add($ins_data);
  190. }
  191. M('lionfish_supply_commiss')->where( array('supply_id' => $commiss['supply_id'] ) )->setInc('money', $commiss['money']);
  192. }
  193. }
  194. }
  195. //----end
  196. }
  197. ?>