title = '订单统计'; $query = $this->_query($this->table); $date = input('date'); if ($date) { $date = str_replace('-', '', $date); $temp = explode('~', $date); $query->whereRaw('(replace(day, "-", "")+0) >= '. $temp[0] . ' and (replace(day, "-", "")+0) <= ' . $temp[1]); } $query->equal('day')->dateBetween('create_at'); $field = '*,(replace(day, "-", "")+0) as day_num'; $order = 'day_num desc,id desc'; $query->field($field); if (input('output') === 'json') { $result = $query->order($order)->page(true, false); $this->success('获取数据列表成功', $result); } else { $query->order($order)->page(); } } /** * 统计信息查看 * @login true * @auth true * @param integer $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function info() { $this->_applyFormToken(); $id = input('id'); $this->_form($this->table, 'info', 'id', [], ['id' => $id]); } /** * 表单数据处理 * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ protected function _form_filter(&$data) { $this->clist = OrderService::instance()->getChannelList(false, false); $this->mlist = OrderService::instance()->getMerchantList(false, false); $this->plist = OrderService::instance()->getProductList(false, false); $this->slist = OrderService::instance()->getServiceList(false, false); $data['data'] = $this->table(json_decode($data['data'], true)); } /** * 数据列表处理 * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ protected function _page_filter(&$data) { $this->total = StatService::instance()->total(); foreach ($data as $k => $v) { if (isset($v['success']) && $v['success'] > 0) { $data[$k]['chengben'] = round($v['product_cash'] / $v['success'], 4); $data[$k]['success_lv'] = round(($v['success']/$v['total']) * 100, 2) . '%'; } else { $data[$k]['chengben'] = 0; } } } private function stat($data) { $table = ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; if ($data['actual_cash']) { $table .= ''; } if ($data['product_cash']) { $table .= ''; } $table .= ''; $table .= '
项目 数值
总金额 '.$data['total'].'
成功金额 '.$data['success'].'
失败金额 '.$data['fail'].'
商户成功金额 '.$data['actual_cash'].'
渠道成功金额 '.$data['product_cash'].'
利润 '.$data['profit'].'
'; return $table; } private function table($data) { $table = ''; if (isset($data['merchant_total'])) { $table .= '
商户分产品明细数据'; $table .= ''; $table .= ''; foreach ($data['merchant_total'] as $ka => $va) { foreach ($va as $k => $v) { if (isset($this->mlist[$ka]) && $this->mlist[$ka] && isset($this->slist[$k]) && isset($v['num'])) { $order_num = ''; if (isset($v['cash']) && $v['cash'] && is_array($v['cash'])) { $id = 'm_' . $ka . '_' . $k; $order_num = '查看明细
商户 产品 金额 实际金额 渠道金额 利润 成本 明细
'; $order_num .= ''; foreach ($v['cash'] as $key => $value) { $key = str_replace('k_', '', $key); $order_num .= ''; } $order_num .= '
面值 金额 实际金额 渠道金额 成本
'.$key.' '.$value['num'].' '.$value['actual_num'].' '.$value['product_num'].' '.round($value['product_num']/$value['num'], 4).'
'; } $actual_num = '0'; if (isset($v['actual_num']) && $v['actual_num']) { $actual_num = $v['actual_num']; } $product_num = '0'; if (isset($v['product_num']) && $v['product_num']) { $product_num = $v['product_num']; } $profit = '0'; if (isset($v['profit']) && $v['profit']) { $profit = $v['profit']; } if ($v['num'] <= 0) { $chengben = 0; } elseif ($product_num <= 0 ) { $chengben = 0; } else { $chengben = round($product_num/$v['num'], 4); } $table .= ''.$this->mlist[$ka]['name'].' '.$this->slist[$k]['name'].' '.$v['num'].' '.$actual_num.' '.$product_num.' '.$profit.' '.$chengben.' '.$order_num.''; /* if (isset($v1['percent_type']) && $v1['percent_type'] == 2) { $v1['profit'] = '+' . $v1['profit']; } else { $v1['profit'] = '-' . $v1['profit']; } $table .= ' '.$this->mlist[$k]['name'].' '.$this->plist[$k1]['name'].'('.$this->clist[$this->plist[$k1]['cid']]['name'].') '.$v1['num'].' '.$v1['percent'].' '.$v1['profit'].''; */ } } } $table .= '
'; } if (isset($data['merchant'])) { $table .= '
商户分渠道明细数据'; $table .= ''; $table .= ''; foreach ($data['merchant'] as $ka => $va) { foreach ($va as $k => $v) { if (isset($this->mlist[$ka]) && $this->mlist[$ka] && isset($this->plist[$k]) && isset($v['num'])) { $order_num = ''; if (isset($v['percent']) && $v['percent'] && is_array($v['percent'])) { $id = 'm_' . $ka . '_' . $k; $order_num = '查看明细
商户 产品 金额 实际金额 渠道金额 利润 成本 明细
'; foreach ($v['percent'] as $key => $value) { $key = str_replace('k_', '', $key); $order_num .= ''; $t = 0; foreach ($value as $k1 => $v1) { $t += $v1['num']; $order_num .= ''; } $order_num .= ''; } $order_num .= '
面值 实际 订单数
'.$k1.' '.$v1['cash'].' '.$v1['num'].'
汇总 分成:'.$key.' '.$t.'
'; } $actual_num = '0'; if (isset($v['actual_num']) && $v['actual_num']) { $actual_num = $v['actual_num']; } $product_num = '0'; if (isset($v['product_num']) && $v['product_num']) { $product_num = $v['product_num']; } $profit = '0'; if (isset($v['profit']) && $v['profit']) { $profit = $v['profit']; } if ($v['num'] <= 0) { $chengben = 0; } elseif ($product_num <= 0 ) { $chengben = 0; } else { $chengben = round($product_num/$v['num'], 4); } $table .= ''.$this->mlist[$ka]['name'].' '.$this->plist[$k]['name'].'('.$this->clist[$this->plist[$k]['cid']]['name'].') '.$v['num'].' '.$actual_num.' '.$product_num.' '.$profit.' '.$chengben.' '.$order_num.''; /* if (isset($v1['percent_type']) && $v1['percent_type'] == 2) { $v1['profit'] = '+' . $v1['profit']; } else { $v1['profit'] = '-' . $v1['profit']; } $table .= ' '.$this->mlist[$k]['name'].' '.$this->plist[$k1]['name'].'('.$this->clist[$this->plist[$k1]['cid']]['name'].') '.$v1['num'].' '.$v1['percent'].' '.$v1['profit'].''; */ } } } $table .= '
'; } if (isset($data['product'])) { $table .= '
渠道明细数据'; $table .= ''; $table .= ''; foreach ($data['product'] as $k => $v) { if (isset($this->plist[$k]) && $this->plist[$k]) { $cid = $this->plist[$k]['cid']; $order_num = ''; if (isset($v['percent']) && $v['percent'] && is_array($v['percent'])) { $id = 'p_' . $ka . '_' . $k; $order_num = '查看明细
渠道 产品 金额 实际金额 明细
'; foreach ($v['percent'] as $key => $value) { $key = str_replace('k_', '', $key); $order_num .= ''; $t = 0; foreach ($value as $k1 => $v1) { $t += $v1['num']; $order_num .= ''; } $order_num .= ''; } $order_num .= '
面值 实际 订单数
'.$k1.' '.$v1['cash'].' '.$v1['num'].'
汇总 分成:'.$key.' '.$t.'
'; } $actual_num = '0'; if (isset($v['actual_num']) && $v['actual_num']) { $actual_num = $v['actual_num']; } $table .= ''.$this->clist[$cid]['name'].' '.$this->plist[$k]['name'].' '.$v['num'].' '.$actual_num.' '.$order_num.''; } } $table .= '
'; } return $table; } /* private function table($data) { $table = ''; if (isset($data['product'])) { $table .= ''; foreach ($data['product'] as $k => $v) { if (isset($this->plist[$k]) && $this->plist[$k]) { if (isset($v['percent_type']) && $v['percent_type'] == 2) { $v['profit'] = '-' . $v['profit']; } else { $v['profit'] = '+' . $v['profit']; } $cid = $this->plist[$k]['cid']; $table .= ''; } } } $table .= '
渠道 产品 金额 分成 利润
'.$this->clist[$cid]['name'].' '.$this->plist[$k]['name'].' '.$v['num'].' '.$v['percent'].' '.$v['profit'].'
'; $table .= ''; if (isset($data['merchant'])) { $table .= ''; foreach ($data['merchant'] as $k => $v) { foreach ($v as $k1 => $v1) { if (isset($this->mlist[$k]) && $this->mlist[$k] && isset($this->plist[$k1]) && isset($v1['num'])) { if (isset($v1['percent_type']) && $v1['percent_type'] == 2) { $v1['profit'] = '+' . $v1['profit']; } else { $v1['profit'] = '-' . $v1['profit']; } $table .= ''; } } } } $table .= '
商户 产品 金额 分成 利润
'.$this->mlist[$k]['name'].' '.$this->plist[$k1]['name'].'('.$this->clist[$this->plist[$k1]['cid']]['name'].') '.$v1['num'].' '.$v1['percent'].' '.$v1['profit'].'
'; return $table; } */ }