SupplyModel.class.php 7.1 KB

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