Sellerbill.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Sellerbill extends BaseSeller {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/sellerbill.lang.php');
  20. }
  21. /**
  22. * 结算列表
  23. *
  24. */
  25. public function index() {
  26. $bill_model = model('bill');
  27. $condition = array();
  28. $condition[] = array('ob_store_id','=',session('store_id'));
  29. $ob_no = input('param.ob_no');
  30. if (preg_match('/^20\d{5,12}$/', $ob_no)) {
  31. $condition[] = array('ob_no','=',$ob_no);
  32. }
  33. $bill_state = intval(input('bill_state'));
  34. if ($bill_state) {
  35. $condition[] = array('ob_state','=',$bill_state);
  36. }
  37. $bill_list = $bill_model->getOrderbillList($condition, '*', 12, 'ob_state asc,ob_no asc');
  38. View::assign('bill_list', $bill_list);
  39. View::assign('show_page', $bill_model->page_info->render());
  40. /* 设置卖家当前菜单 */
  41. $this->setSellerCurMenu('Sellerbill');
  42. /* 设置卖家当前栏目 */
  43. $this->setSellerCurItem('seller_slide');
  44. return View::fetch($this->template_dir.'index');
  45. }
  46. /**
  47. * 查看结算单详细
  48. *
  49. */
  50. public function show_bill() {
  51. $ob_no = input('param.ob_no');
  52. if (!$ob_no) {
  53. $this->error(lang('param_error'));
  54. }
  55. $bill_model = model('bill');
  56. $bill_info = $bill_model->getOrderbillInfo(array('ob_no' => $ob_no,'ob_store_id'=>session('store_id')));
  57. if (!$bill_info) {
  58. $this->error(lang('param_error'));
  59. }
  60. $order_condition = array();
  61. $order_condition[] = array('ob_no','=',$ob_no);
  62. $order_condition[] = array('order_state','=',ORDER_STATE_SUCCESS);
  63. $order_condition[] = array('store_id','=',$bill_info['ob_store_id']);
  64. $query_start_date = input('get.query_start_date');
  65. $query_end_date = input('get.query_end_date');
  66. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  67. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  68. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  69. $end_unixtime = $if_end_date ? (strtotime($query_end_date)+86399) : null;
  70. if ($if_start_date) {
  71. if($if_start_date){
  72. $order_condition[] = array('finnshed_time','>=', $start_unixtime);
  73. }
  74. }
  75. if ($if_end_date) {
  76. if($if_end_date){
  77. $order_condition[] = array('finnshed_time','<=', $end_unixtime);
  78. }
  79. }
  80. $query_order_no = input('get.query_order_no');
  81. $type = input('param.type');
  82. if ($type == 'vrorder') {
  83. if (preg_match('/^\d{8,20}$/', $query_order_no)) {
  84. $order_condition[] = array('order_sn','=',$query_order_no);
  85. }
  86. $vrorder_model = model('vrorder');
  87. $order_list = $vrorder_model->getVrorderList($order_condition, 20,'SUM(ROUND(order_amount*commis_rate/100,2)) AS commis_amount,SUM(ROUND(refund_amount*commis_rate/100,2)) AS return_commis_amount,order_amount,refund_amount,order_sn,buyer_name,add_time,finnshed_time,order_id');
  88. foreach($order_list as $key => $val){
  89. if(!$val['order_id']){
  90. $order_list=array();
  91. break;
  92. }
  93. //分销佣金
  94. $inviter_info=Db::name('orderinviter')->where(array('orderinviter_order_id' => $key, 'orderinviter_valid' => 1, 'orderinviter_order_type' => 1))->field('SUM(orderinviter_money) AS ob_inviter_totals')->find();
  95. $order_list[$key]['inviter_amount']= ds_price_format($inviter_info['ob_inviter_totals']);
  96. }
  97. View::assign('order_list', $order_list);
  98. View::assign('show_page', $vrorder_model->page_info->render());
  99. $sub_tpl_name = 'show_vrorder_list';
  100. /* 设置卖家当前菜单 */
  101. $this->setSellerCurMenu('Sellerbill');
  102. /* 设置卖家当前栏目 */
  103. $this->setSellerCurItem('seller_slide');
  104. } elseif ($type == 'cost') {
  105. //店铺费用
  106. $storecost_model = model('storecost');
  107. $cost_condition = array();
  108. $cost_condition[] = array('storecost_store_id','=',$bill_info['ob_store_id']);
  109. $cost_condition[] = array('storecost_time','between',[$bill_info['ob_startdate'],$bill_info['ob_enddate']]);
  110. $store_cost_list = $storecost_model->getStorecostList($cost_condition, 20);
  111. //取得店铺名字
  112. $store_info = model('store')->getStoreInfoByID($bill_info['ob_store_id']);
  113. View::assign('cost_list', $store_cost_list);
  114. View::assign('store_info', $store_info);
  115. View::assign('show_page', $storecost_model->page_info->render());
  116. $sub_tpl_name = 'show_cost_list';
  117. /* 设置卖家当前菜单 */
  118. $this->setSellerCurMenu('Sellerbill');
  119. /* 设置卖家当前栏目 */
  120. $this->setSellerCurItem('seller_slide');
  121. } else {
  122. if (preg_match('/^\d{8,20}$/', $query_order_no)) {
  123. $order_condition[] = array('order_sn','=',$query_order_no);
  124. }
  125. //订单列表
  126. $order_model = model('order');
  127. $order_list = $order_model->getOrderList($order_condition, 20);
  128. //然后取订单商品佣金
  129. $order_id_array = array();
  130. if (is_array($order_list)) {
  131. foreach ($order_list as $order_info) {
  132. $order_id_array[] = $order_info['order_id'];
  133. }
  134. }
  135. $order_goods_condition = array();
  136. $order_goods_condition[]=array('order_id','in', $order_id_array);
  137. $field = 'SUM(ROUND(goods_pay_price*commis_rate/100,2)) as commis_amount,order_id';
  138. $commis_list = $order_model->getOrdergoodsList($order_goods_condition, $field, 0, null, '', 'order_id', 'order_id');
  139. foreach($commis_list as $key => $val){
  140. $return_commis_amount=0;
  141. $refund_info=Db::name('refundreturn')->alias('refundreturn')->join('ordergoods ordergoods', 'refundreturn.order_goods_id = ordergoods.rec_id')->where(array(array('refundreturn.order_id' ,'=', $key), array('refundreturn.refund_state' ,'=', 3), array('refundreturn.order_goods_id','>', 0)))->field('SUM(ROUND(refundreturn.refund_amount*ordergoods.commis_rate/100,2)) AS ob_commis_return_totals')->find();
  142. $return_commis_amount=$refund_info['ob_commis_return_totals'];
  143. $commis_list[$key]['return_commis_amount']=$return_commis_amount;
  144. //分销佣金
  145. $inviter_info=Db::name('orderinviter')->where(array('orderinviter_order_id' => $key, 'orderinviter_valid' => 1, 'orderinviter_order_type' => 0))->field('SUM(orderinviter_money) AS ob_inviter_totals')->find();
  146. $commis_list[$key]['inviter_amount']=$inviter_info['ob_inviter_totals'];
  147. //平台代金券
  148. $mallvoucher_info=Db::name('ordercommon')->where(array('order_id' => $key))->field('mallvoucher_price')->find();
  149. $commis_list[$key]['mall_voucher_totals']=number_format($mallvoucher_info['mallvoucher_price'], 2);
  150. }
  151. View::assign('commis_list', $commis_list);
  152. View::assign('order_list', $order_list);
  153. $order_list_page = Db::name('order')->where($order_condition)->paginate(['list_rows'=>20,'query' => request()->param()],false);
  154. View::assign('show_page', $order_list_page->render());
  155. $sub_tpl_name = 'show_order_list';
  156. /* 设置卖家当前菜单 */
  157. $this->setSellerCurMenu('Sellerbill');
  158. /* 设置卖家当前栏目 */
  159. $this->setSellerCurItem('seller_slide');
  160. }
  161. View::assign('bill_info', $bill_info);
  162. return View::fetch($this->template_dir.$sub_tpl_name);
  163. }
  164. /**
  165. * 打印结算单
  166. *
  167. */
  168. public function bill_print() {
  169. $ob_no = input('param.ob_no');
  170. if (!$ob_no) {
  171. $this->error(lang('param_error'));
  172. }
  173. $bill_model = model('bill');
  174. $condition = array();
  175. $condition[] = array('ob_no','=',$ob_no);
  176. $condition[] = array('ob_store_id','=',session('store_id'));
  177. $condition[] = array('ob_state','=',BILL_STATE_SUCCESS);
  178. $bill_info = $bill_model->getOrderbillInfo($condition);
  179. if (!$bill_info) {
  180. $this->error(lang('param_error'));
  181. }
  182. View::assign('bill_info', $bill_info);
  183. return View::fetch($this->template_dir.'bill_print');
  184. }
  185. /**
  186. * 店铺确认出账单
  187. *
  188. */
  189. public function confirm_bill() {
  190. $ob_no = input('param.ob_no');
  191. if (!$ob_no) {
  192. ds_json_encode(10001,lang('param_error'));
  193. }
  194. $bill_model = model('bill');
  195. $condition = array();
  196. $condition[] = array('ob_no','=',$ob_no);
  197. $condition[] = array('ob_store_id','=',session('store_id'));
  198. $condition[] = array('ob_state','=',BILL_STATE_CREATE);
  199. $bill_info=$bill_model->getOrderbillInfo($condition);
  200. if(!$bill_info){
  201. ds_json_encode(10001,lang('bill_is_not_exist'));
  202. }
  203. if(request()->isPost()){
  204. $update = $bill_model->editOrderbill(array('ob_state' => BILL_STATE_STORE_COFIRM,'ob_seller_content'=>input('post.ob_seller_content')), $condition);
  205. if ($update) {
  206. ds_json_encode(10000,lang('ds_common_op_succ'));
  207. } else {
  208. ds_json_encode(10001,lang('ds_common_op_fail'));
  209. }
  210. }else{
  211. return View::fetch($this->template_dir.'bill_confirm');
  212. }
  213. }
  214. /**
  215. * 用户中心右边,小导航
  216. *
  217. * @param string $menu_type 导航类型
  218. * @param string $menu_key 当前导航的menu_key
  219. * @return
  220. */
  221. function getSellerItemList() {
  222. $ob_no = input('param.ob_no');
  223. if (request()->action()=='index') {
  224. $menu_array = array(
  225. array(
  226. 'name' => 'list',
  227. 'text' => lang('physical_settlement'),
  228. 'url' => (string)url('Sellerbill/index')
  229. ),
  230. );
  231. }else if(request()->action()=='show_bill'){
  232. $menu_array = array(
  233. array(
  234. 'name' => 'order_list',
  235. 'text' => lang('order_list'),
  236. 'url' => (string)url('Sellerbill/show_bill', ['ob_no' => $ob_no])
  237. ),
  238. array(
  239. 'name' => 'vrorder_list',
  240. 'text' => lang('vrorder_list'),
  241. 'url' => (string)url('Sellerbill/show_bill', ['type'=>'vrorder','ob_no' => $ob_no])
  242. ),
  243. array(
  244. 'name' => 'cost_list',
  245. 'text' => lang('cost_list'),
  246. 'url' => (string)url('Sellerbill/show_bill', ['type'=>'cost','ob_no' => $ob_no])
  247. ),
  248. );
  249. }
  250. return $menu_array;
  251. }
  252. }