CommonorderModel.class.php 23 KB

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