Sellerbill.php 12 KB

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