CommonorderModel.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Model;
  10. class CommonorderModel{
  11. //TODO....设置售后期的情况下进行确认收货,跟系统自动结算两个方法
  12. /**
  13. 获取一个订单中,商品的数量,
  14. **/
  15. public function get_order_goods_quantity( $order_id,$order_goods_id=0)
  16. {
  17. $where = "";
  18. if( !empty($order_goods_id) && $order_goods_id >0 )
  19. {
  20. $where .= " and order_goods_id={$order_goods_id} ";
  21. }
  22. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  23. //原来有的数量
  24. $total_quantity = M('lionfish_comshop_order_goods')->where( "order_id ={$order_id} {$where}" )->sum('quantity');
  25. $total_quantity = empty($total_quantity) ? 0 : $total_quantity;
  26. $refund_quantity = $this->refund_order_goods_quantity( $order_id,$order_goods_id,$uniacid);
  27. $surplus_quantity = $total_quantity - $refund_quantity;
  28. if($order_info['delivery'] == 'hexiao'){
  29. $used_quantity = D('Home/Salesroom')->get_hexiao_order_goods_used_quantity($order_id,$order_goods_id);
  30. $surplus_quantity = $surplus_quantity - $used_quantity;
  31. }
  32. return $surplus_quantity;
  33. }
  34. /**
  35. 已经退掉的订单商品数量
  36. **/
  37. public function refund_order_goods_quantity( $order_id,$order_goods_id=0 )
  38. {
  39. $where = "";
  40. if( !empty($order_goods_id) && $order_goods_id >0 )
  41. {
  42. $where .= " and order_goods_id={$order_goods_id} ";
  43. }
  44. $refund_quantity = M('lionfish_comshop_order_goods_refund')->where("order_id ={$order_id} {$where}")->sum('real_refund_quantity');
  45. $refund_quantity = empty($refund_quantity) ? 0 : $refund_quantity;
  46. return $refund_quantity;
  47. }
  48. /**
  49. 该笔子订单已经退款了多少钱
  50. **/
  51. public function get_order_goods_refund_money( $order_id,$order_goods_id )
  52. {
  53. $where = "";
  54. if( !empty($order_goods_id) && $order_goods_id >0 )
  55. {
  56. $where .= " and order_goods_id={$order_goods_id} ";
  57. }
  58. $refund_money = M('lionfish_comshop_order_goods_refund')->where( "order_id ={$order_id} {$where}" )->sum('money');
  59. $refund_money = empty($refund_money) ? 0 : $refund_money;
  60. return $refund_money;
  61. }
  62. /**
  63. 获取订单商品支付的金额公共方法
  64. **/
  65. public function get_order_goods_paymoney( $order_goods_id )
  66. {
  67. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->find();
  68. if( empty($order_goods_info) )
  69. {
  70. return 0;
  71. }else{
  72. $pay_free = $order_goods_info['total'] + $order_goods_info['shipping_fare']-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money']-$order_goods_info['score_for_money'];
  73. $pay_free = round($pay_free, 2);
  74. $order_info = M('lionfish_comshop_order')->field('type')->where( array('order_id' => $order_goods_info['order_id']) )->find();
  75. if( $order_info['type'] == 'integral' )
  76. {
  77. $pay_free = round($order_goods_info['shipping_fare'], 2);
  78. }
  79. return $pay_free;
  80. }
  81. }
  82. /**
  83. 获取订单金额--公共方法
  84. @auth fish
  85. **/
  86. public function get_order_paymoney( $order_id )
  87. {
  88. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  89. if( empty($order_info) )
  90. {
  91. return 0;
  92. }else{
  93. $pay_free = $order_info['total'] -$order_info['voucher_credit']-$order_info['fullreduction_money']-$order_info['score_for_money'];
  94. if( $order_info['type'] != 'integral' )
  95. {
  96. if($order_info['is_free_shipping_fare'] == 0 ){
  97. $pay_free += $order_info['shipping_fare'];
  98. }
  99. }
  100. $pay_free = round($pay_free, 2);
  101. return $pay_free;
  102. }
  103. }
  104. /**
  105. *
  106. * 获取订单已经退款了多少钱
  107. */
  108. public function order_refund_totalmoney( $order_id )
  109. {
  110. $total_money = M('lionfish_comshop_order_goods_refund')->where( array('order_id' =>$order_id ) )->sum('money');
  111. if( empty($total_money) )
  112. {
  113. $total_money = 0;
  114. }
  115. return $total_money;
  116. }
  117. /**
  118. * 获取订单商品 购买支付时,抵扣用了多少积分
  119. */
  120. public function get_order_goods_buyscore($order_id, $order_goods_id)
  121. {
  122. $integral_flow_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id, 'order_goods_id' =>$order_goods_id,'type' => 'orderbuy' ) )->find();
  123. if( empty($integral_flow_info) )
  124. {
  125. return 0;
  126. }else{
  127. return $integral_flow_info['score'];
  128. }
  129. }
  130. /**
  131. * 退款积分
  132. */
  133. public function refund_order_goods_intrgral( $order_id, $order_goods_id ,$score )
  134. {
  135. $in_data = array();
  136. $in_data['uniacid'] = 0;
  137. $in_data['order_goods_id'] = $order_goods_id;
  138. $in_data['order_id'] = $order_id;
  139. $in_data['refund_score'] = $score;
  140. $in_data['addtime'] = time();
  141. $res = M('lionfish_comshop_order_goods_refund_intrgral')->add($in_data);
  142. }
  143. /**
  144. 退款整笔订单
  145. @auth lionfish
  146. @param is_back_buyscore 是否退积分,0否,1 是
  147. mail 353399459@qq.com
  148. time:2020-03-07
  149. **/
  150. public function refund_one_order( $order_id ,$is_back_buyscore = 0)
  151. {
  152. $_GPC = I('request.');
  153. $order_goods_list = M('lionfish_comshop_order_goods')->field('order_goods_id,quantity,shipping_fare,fenbi_li')->where( array('order_id' => $order_id , 'is_refund_state' => 0) )->select();
  154. if( !empty($order_goods_list) )
  155. {
  156. foreach( $order_goods_list as $val)
  157. {
  158. $order_goods_id = $val['order_goods_id'];
  159. $refund_shipping_fare = 0;
  160. if( $is_back_buyscore == 0)
  161. {
  162. $this->refund_order_goods_intrgral( $order_id, $order_goods_id ,0 );
  163. }else if($is_back_buyscore == 1){
  164. $integral_flow_info = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id, 'order_goods_id' =>$order_goods_id,'type' => 'orderbuy' ) )->find();
  165. if( !empty($integral_flow_info) )
  166. {
  167. $has_refflow_score = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id, 'order_goods_id' =>$order_goods_id,'type' => 'refundorder' ) )->sum('score');
  168. if( !empty($has_refflow_score) && $has_refflow_score > 0 )
  169. {
  170. $integral_flow_info['score'] -= $has_refflow_score;
  171. if($integral_flow_info['score'] < 0)
  172. {
  173. $integral_flow_info['score'] =0;
  174. }
  175. }
  176. $this->refund_order_goods_intrgral( $order_id, $order_goods_id ,$integral_flow_info['score'] );
  177. }
  178. }else if( $is_back_buyscore == 2)//退运费
  179. {
  180. $has_refund_shipping_fare = M('lionfish_comshop_order_goods_refund')->where( array('order_goods_id' => $val['order_goods_id'] ) )->sum('refund_shipping_fare');
  181. $refund_shipping_fare = $val['shipping_fare']-$has_refund_shipping_fare;
  182. }
  183. $is_has_refund_deliveryfree = D('Home/Front')->get_config_by_name('is_has_refund_deliveryfree');
  184. $is_has_refund_deliveryfree = !isset($is_has_refund_deliveryfree) || $is_has_refund_deliveryfree == 1 ? 1:0;
  185. if($is_has_refund_deliveryfree == 0){//不退配送费
  186. $refund_shipping_fare = $val['shipping_fare'];
  187. }
  188. $pay_total_money = $this->get_order_goods_paymoney( $order_goods_id );
  189. $has_refund_money = $this->get_order_goods_refund_money( $order_id,$order_goods_id );
  190. $has_refund_quantity = $this->refund_order_goods_quantity( $order_id,$order_goods_id);
  191. $real_refund_quantity = $val['quantity']- $has_refund_quantity;
  192. $refund_quantity = $real_refund_quantity - $has_refund_quantity;
  193. //$refund_money = round($pay_total_money - $has_refund_money - $val['shipping_fare'],2);
  194. $refund_money_sum = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0 ? floatval($_GPC['refund_money']) : 0;
  195. $refund_money = $refund_money_sum * $val['fenbi_li'];
  196. $is_back_sellcount = 1;
  197. $this->ins_order_goods_refund($order_id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money, $is_back_sellcount, $refund_shipping_fare);
  198. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->save( array('is_refund_state' => 1 ) );
  199. }
  200. }
  201. }
  202. /**
  203. 每日订单-商品购买记录每日销量
  204. **/
  205. public function inc_daygoods_buy( $goods_id, $quantity )
  206. {
  207. //begin
  208. $today_zero_time = strtotime( date('Y-m-d').' 00:00:00' );
  209. //$clear_goodsdaysales = S('clear_goodsdaysales');
  210. $clear_goodsdaysales = D('Home/Front')->get_config_by_name('clear_goodsdaysales');
  211. if( !isset($today_zero_time) || $clear_goodsdaysales != $today_zero_time )
  212. {
  213. D('Seller/Commonorder')->clear_goods_daysales();
  214. //S('clear_goodsdaysales', $today_zero_time );
  215. $config_data = array();
  216. $config_data['clear_goodsdaysales'] = $today_zero_time;
  217. D('Seller/Config')->update($config_data);
  218. }
  219. //end
  220. M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->setInc('day_salescount', $quantity);
  221. }
  222. /**
  223. 每日订单-商品退款每日销量
  224. **/
  225. public function dec_daygoods_refund( $goods_id, $quantity )
  226. {
  227. M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->setInc('day_salescount', -$quantity);
  228. }
  229. /**
  230. 清理商品 每日销量
  231. **/
  232. public function clear_goods_daysales()
  233. {
  234. M('lionfish_comshop_goods')->where( "1=1" )->save( array('day_salescount' => 0 ) );
  235. }
  236. /**
  237. 插入子订单退款
  238. * $refund_shipping_fare 退款运费
  239. **/
  240. public function ins_order_goods_refund($order_id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money, $is_back_sellcount, $refund_shipping_fare)
  241. {
  242. //计算需要抵扣多少佣金 ims_ lionfish_comshop_order
  243. $commiss_info = M('lionfish_community_head_commiss_order')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and type='orderbuy' " )->find();
  244. // lionfish_comshop_order_goods
  245. $order_goods_info = M('lionfish_comshop_order_goods')->where( " order_goods_id={$order_goods_id} " )->find();
  246. //order_status_id
  247. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  248. $now_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  249. $now_end_time = $now_begin_time + 86400;
  250. //今日订单今日退款成功减去今日销量
  251. if( $order_info['date_added'] >= $now_begin_time && $order_info['date_added'] < $now_end_time )
  252. {
  253. $this->dec_daygoods_refund( $order_goods_info['goods_id'], $real_refund_quantity );
  254. }
  255. $refund_data = array();
  256. $refund_data['order_goods_id'] = $order_goods_id;
  257. $refund_data['order_id'] = $order_id;
  258. $refund_data['uniacid'] = 0;
  259. $refund_data['real_refund_quantity'] = $real_refund_quantity;
  260. $refund_data['quantity'] = $refund_quantity;
  261. $refund_data['money'] = $refund_money;
  262. $refund_data['refund_shipping_fare'] = $refund_shipping_fare;
  263. $refund_data['order_status_id'] = $order_info['order_status_id'];
  264. $refund_data['is_back_quantity'] = $is_back_sellcount;
  265. //--- 以下需要计算了 refundorder
  266. $refund_data['back_score_for_money'] = 0;//退还积分兑换商品的积分 orderbuy
  267. $refund_data['back_send_score'] = 0; //退还赠送积分 goodsbuy
  268. $refund_data['back_head_orderbuycommiss'] = 0; //退还团长佣金
  269. $refund_data['back_head_supplycommiss'] = 0; //退还供应商佣金
  270. $refund_data['back_head_commiss_1'] = 0; //退1级团长佣金
  271. $refund_data['back_head_commiss_2'] = 0; //退2级团长佣金
  272. $refund_data['back_head_commiss_3'] = 0; //退3级团长佣金
  273. $refund_data['back_member_commiss_1'] = 0; //退会员1级佣金
  274. $refund_data['back_member_commiss_2'] = 0; //退会员2级佣金
  275. $refund_data['back_member_commiss_3'] = 0; //退会员3级佣金
  276. $refund_data['addtime'] = time(); //添加时间
  277. if( !empty($commiss_info) && $commiss_info['state'] == 1 )
  278. {
  279. //已经结算了
  280. //INSERT
  281. $id = M('lionfish_comshop_order_goods_refund')->add( $refund_data );
  282. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_money', $refund_money );
  283. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_quantity', $real_refund_quantity );
  284. //has_refund_money
  285. return $id;
  286. }else{
  287. //未结算的
  288. $score_for_money_info = M('lionfish_comshop_member_integral_flow')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and type='orderbuy' " )->find();
  289. if( !empty($score_for_money_info) )
  290. {
  291. if( $refund_money > 0 && $pay_total_money > 0)
  292. {
  293. $refund_data['back_score_for_money'] = ($refund_money / $pay_total_money ) * $score_for_money_info['score'] ;
  294. }else{
  295. $refund_data['back_score_for_money'] = 0 ;
  296. }
  297. //$refund_money
  298. $refund_intrgral_info = M('lionfish_comshop_order_goods_refund_intrgral')->where( array('order_goods_id' =>$order_goods_id ,'order_id' => $order_id ) )->order('id desc')->find();
  299. if( !empty($refund_intrgral_info) )
  300. {
  301. $refund_data['back_score_for_money'] = $refund_intrgral_info['refund_score'];
  302. }
  303. //退回去给用户
  304. D('Admin/Member')->sendMemberPointChange($order_info['member_id'],$refund_data['back_score_for_money'], 0 ,'退款'.$real_refund_quantity.'个商品,增加积分','refundorder', $order_info['order_id'] ,$order_goods_id );
  305. $send_score_info = M('lionfish_comshop_member_integral_flow')->where(" order_id={$order_id} and order_goods_id={$order_goods_id} and type='goodsbuy' ")->find();
  306. }
  307. if( !empty($send_score_info) )
  308. {
  309. $refund_data['back_send_score'] = intval( ($refund_money / $pay_total_money ) * $send_score_info['score'] );
  310. $refund_data['back_send_score'] = $refund_data['back_send_score'] <= 0 ? 0 : $refund_data['back_send_score'];
  311. //减去相应的分数,然后插入
  312. M('lionfish_comshop_member_integral_flow')->where( " order_id={$order_id} and type='goodsbuy' and order_goods_id={$order_goods_id} " )->setInc('score', -$refund_data['back_send_score']);
  313. }
  314. //$refund_data['back_head_orderbuycommiss'] = 0; //退还团长佣金
  315. $head_commisslist = M('lionfish_community_head_commiss_order')->where( " type in ('orderbuy','commiss') and order_id={$order_id} and order_goods_id={$order_goods_id} and state=0 " )->select();
  316. if( !empty($head_commisslist) )
  317. {
  318. foreach( $head_commisslist as $val )
  319. {
  320. if( $val['type'] == 'orderbuy' )
  321. {
  322. //$goods_shipping_fare =$real_refund_quantity * round( ($real_refund_quantity / $order_goods_info['quantity'] ) * $order_goods_info['shipping_fare'] , 2);
  323. $head_orderbuycommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  324. $head_orderbuycommiss = $head_orderbuycommiss <= 0 ? 0 : $head_orderbuycommiss;
  325. M('lionfish_community_head_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$head_orderbuycommiss);
  326. $refund_data['back_head_orderbuycommiss'] = $head_orderbuycommiss;
  327. }
  328. if( $val['type'] == 'commiss' )
  329. {
  330. $val['money'] = $val['money'] - $val['add_shipping_fare'];
  331. if( $val['level'] == 1 )
  332. {
  333. $head_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  334. $head_levelcommiss = $head_levelcommiss <= 0 ? 0 : $head_levelcommiss;
  335. M('lionfish_community_head_commiss_order')->where( "id=".$val['id'] )->setInc('money', -$head_levelcommiss);
  336. $refund_data['back_head_commiss_1'] = $head_levelcommiss;
  337. }
  338. if( $val['level'] == 2 )
  339. {
  340. $head_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  341. $head_levelcommiss = $head_levelcommiss <= 0 ? 0 : $head_levelcommiss;
  342. M('lionfish_community_head_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$head_levelcommiss);
  343. $refund_data['back_head_commiss_2'] = $head_levelcommiss;
  344. }
  345. if( $val['level'] == 3 )
  346. {
  347. $head_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  348. $head_levelcommiss = $head_levelcommiss <= 0 ? 0 : $head_levelcommiss;
  349. M('lionfish_community_head_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$head_levelcommiss);
  350. $refund_data['back_head_commiss_3'] = $head_levelcommiss;
  351. }
  352. }
  353. }
  354. }
  355. //back_head_supplycommiss ims_lionfish_supply_commiss_order ims_
  356. $supply_commisslist = M('lionfish_supply_commiss_order')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and state=0 " )->find();
  357. if( !empty($supply_commisslist) )
  358. {
  359. $supply_orderbuycommiss = round( ($refund_money / $pay_total_money ) * $supply_commisslist['total_money'] , 2);
  360. $supply_orderbuycommiss_money = round( ($refund_money / $pay_total_money ) * $supply_commisslist['money'] , 2);
  361. $supply_orderbuycommiss = $supply_orderbuycommiss <= 0 ? 0 : $supply_orderbuycommiss;
  362. $supply_orderbuycommiss_money = $supply_orderbuycommiss_money <= 0 ? 0 : $supply_orderbuycommiss_money;
  363. M('lionfish_supply_commiss_order')->where( array('id' =>$supply_commisslist['id'] ) )->setInc('money', -$supply_orderbuycommiss_money );
  364. M('lionfish_supply_commiss_order')->where( array('id' =>$supply_commisslist['id'] ) )->setInc('total_money', -$supply_orderbuycommiss );
  365. $refund_data['back_head_supplycommiss'] = $supply_orderbuycommiss;
  366. }
  367. //
  368. //$refund_data['back_member_commiss_1'] = 0; //退会员1级佣金
  369. //$refund_data['back_member_commiss_2'] = 0; //退会员2级佣金
  370. //$refund_data['back_member_commiss_3'] = 0; //退会员3级佣金
  371. $member_commisslist = M('lionfish_comshop_member_commiss_order')->where( " order_id={$order_id} and order_goods_id={$order_goods_id} and state=0 " )->select();
  372. if( !empty($member_commisslist) )
  373. {
  374. foreach( $member_commisslist as $val )
  375. {
  376. if( $val['level'] == 1 )
  377. {
  378. $member_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  379. $member_levelcommiss = $member_levelcommiss <= 0 ? 0 : $member_levelcommiss;
  380. M('lionfish_comshop_member_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$member_levelcommiss );
  381. $refund_data['back_member_commiss_1'] = $member_levelcommiss;
  382. }
  383. if( $val['level'] == 2 )
  384. {
  385. $member_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  386. $member_levelcommiss = $member_levelcommiss <= 0 ? 0 : $member_levelcommiss;
  387. M('lionfish_comshop_member_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$member_levelcommiss);
  388. $refund_data['back_member_commiss_2'] = $member_levelcommiss;
  389. }
  390. if( $val['level'] == 3 )
  391. {
  392. $member_levelcommiss = round( ($refund_money / $pay_total_money ) * $val['money'] , 2);
  393. $member_levelcommiss = $member_levelcommiss <= 0 ? 0 : $member_levelcommiss;
  394. M('lionfish_comshop_member_commiss_order')->where( array('id' => $val['id'] ) )->setInc('money', -$member_levelcommiss );
  395. $refund_data['back_member_commiss_3'] = $member_levelcommiss;
  396. }
  397. }
  398. }
  399. //INSERT
  400. $id = M('lionfish_comshop_order_goods_refund')->add( $refund_data );
  401. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_money', $refund_money );
  402. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id) )->setInc('has_refund_quantity', $real_refund_quantity );
  403. //has_refund_money
  404. return $id;
  405. }
  406. }
  407. /**
  408. 后台订单详情 部分商品退款操作,检测是否整单退款
  409. TODO....
  410. **/
  411. public function check_refund_order_goods_status($order_id, $order_goods_id, $refund_money,$is_back_sellcount,$real_refund_quantity, $refund_quantity,$is_refund_shippingfare, $ref_comment = '后台操作立即退款,')
  412. {
  413. $refund_total_quantity = M('lionfish_comshop_order_goods_refund')->where( "order_id={$order_id} and order_goods_id={$order_goods_id} " )->sum('quantity');
  414. $order_goods_info = M('lionfish_comshop_order_goods')->where( "order_goods_id={$order_goods_id} " )->find();
  415. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  416. if( $refund_total_quantity >= $order_goods_info['quantity'] || $order_goods_info['has_refund_money'] >= $order_goods_info['total'])
  417. {
  418. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->save( array('is_refund_state' => 1 ) );
  419. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  420. $is_all_refund = true;
  421. foreach($order_goods_list as $val )
  422. {
  423. if($val['is_refund_state'] != 1)
  424. {
  425. $is_all_refund = false;
  426. }
  427. }
  428. if($is_all_refund)
  429. {
  430. $comment = $ref_comment.'退款金额:'.$refund_money.'元';
  431. if( $order_info['type'] == 'integral' )
  432. {
  433. if( $order_info['shipping_fare'] > 0 )
  434. {
  435. $comment = $ref_comment.'退款金额:'.$order_info['shipping_fare'].'元,积分:'.$order_info['total'];
  436. }else{
  437. $comment = $ref_comment.'退还积分:'.$order_info['total'];
  438. }
  439. }
  440. if($is_refund_shippingfare == 1)
  441. {
  442. //最后一次金额
  443. $shipping_fare = M('lionfish_comshop_order_goods_refund')->where( "order_id={$order_id} and order_goods_id={$order_goods_id} " )->order('id desc')->find();
  444. if(!empty($shipping_fare['refund_shipping_fare'])){
  445. $comment .= '. 退配送费:'.$shipping_fare['refund_shipping_fare'].'元';
  446. }
  447. }
  448. if($is_back_sellcount == 1)
  449. {
  450. $comment .= '. 退款商品数量:'.$real_refund_quantity.'. 退库存/扣销量:'.$refund_quantity;
  451. }else{
  452. $comment .= '. 退款商品数量:'.$real_refund_quantity.'. 不退库存/不扣销量';
  453. }
  454. $order_history = array();
  455. $order_history['uniacid'] = $_W['uniacid'];
  456. $order_history['order_id'] = $order_id;
  457. $order_history['order_status_id'] = 7;
  458. $order_history['notify'] = 0;
  459. $order_history['comment'] = $comment;
  460. $order_history['date_added'] = time();
  461. M('lionfish_comshop_order_history')->add( $order_history );
  462. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 7) );
  463. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  464. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  465. {
  466. D('Seller/Printaction')->check_print_order($order_id,'后台操作取消订单');
  467. D('Seller/Printaction')->check_print_order2($order_id,'后台操作取消订单');
  468. }
  469. }
  470. }else{
  471. }
  472. }
  473. /**
  474. 整单退款,切割退款金额到子订单
  475. **/
  476. public function def_order_refund_togoods( $order_id, $refund_money,$free_tongji,$is_refund_shippingfare )
  477. {
  478. }
  479. }
  480. ?>