| | |
| | | case "getUserList": |
| | | return $userApi->getUserList($retData["repData"]); |
| | | case "getUserOrderList": |
| | | return $userApi->getUserOrderList($retData["repData"]); |
| | | return $userApi->getUserOrderList($retData["repData"]); |
| | | case "getUserOrderDetail": |
| | | return $userApi->getUserOrderDetail($retData["repData"]); |
| | | case "getAgentList": |
| | | return $userApi->getAgentList($retData["repData"]); |
| | | default: http_response_code(404); |
| | | } |
| | | return array(); |
| | |
| | | |
| | | public function getUserList($param) |
| | | { |
| | | |
| | | $sqlParam = array(':invitationCode' => $param["invitationCode"]); |
| | | if (!empty($param['uuid'])) { |
| | | $invitationCode = pdo_getcolumn('agent', array('uuid' => $param['uuid']), 'invitation_code', 1); |
| | | $sqlParam = array(':invitationCode' => $invitationCode); |
| | | } else { |
| | | $sqlParam = array(':invitationCode' => $param["invitationCode"]); |
| | | } |
| | | |
| | | $sql = "SELECT u.uid,u.username,u.status,u.starttime,u.joindate,u.endtime,p.qq,p.mobile from ims_users u left join ims_users_profile p on u.uid = p.uid where invitation_code=:invitationCode"; |
| | | if ($param['user_name'] != null && $param['user_name'] != ''){ |
| | | $sql = $sql." and u.username like '%".$param["user_name"]."%' "; |
| | |
| | | |
| | | if ($param['phone_number'] != null && $param['phone_number'] != ''){ |
| | | $sql = $sql." and p.mobile like '%".$param['phone_number']."%' "; |
| | | $sqlParam[":phone_number"] = $param["phone_number"]; |
| | | } |
| | | |
| | | if ($param['status'] != null && $param['status'] != ''){ |
| | |
| | | } |
| | | |
| | | if ($param['min_date'] != null && $param['min_date'] != ''){ |
| | | $sql = $sql.' and u.joindate<:min_date'; |
| | | $sql = $sql.' and u.joindate>=:min_date'; |
| | | $sqlParam[":min_date"] = $param["min_date"]; |
| | | } |
| | | |
| | | if ($param['max_date'] != null && $param['max_date'] != ''){ |
| | | $sql = $sql.' and u.joindate>:max_date'; |
| | | $sql = $sql.' and u.joindate<=:max_date'; |
| | | $sqlParam[":max_date"] = $param["max_date"]; |
| | | } |
| | | return pdo_fetchall($sql,$sqlParam); |
| | | $result = array(); |
| | | // 分页查询 |
| | | $result['count'] = count(pdo_fetchall($sql,$sqlParam)); |
| | | $result['list'] = pdo_fetchall($sql.' limit '.$param['firstRow'].",".$param['listRows'],$sqlParam); |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | public function getUserOrderList($param) { |
| | | $sqlParam = array(':invitationCode' => $param["invitationCode"]); |
| | | $sql = "select `date`, COUNT(id), SUM(amount) from ( |
| | | select *, FROM_UNIXTIME(endtime,'%Y年%m月') as date from ims_site_store_order where buyerid in (select uid from ims_users where invitation_code = :invitationCode) |
| | | ) as `order` ORDER BY `date`"; |
| | | return pdo_fetchall($sql,$sqlParam); |
| | | if (!empty($param['uuid'])) { |
| | | $invitationCode = pdo_getcolumn('agent', array('uuid' => $param['uuid']), 'invitation_code', 1); |
| | | $sqlParam = array(':invitationCode' => $invitationCode); |
| | | $rate_level = pdo_getcolumn('agent', array('invitation_code' => $param['invitationCode']), 'rate_level_2', 1); |
| | | $sqlParam[':rate_level'] = $rate_level; |
| | | } else { |
| | | $sqlParam = array(':invitationCode' => $param["invitationCode"]); |
| | | } |
| | | // 自己的场合,使用rate_level_1,下级代理商的场合,使用rate_level_2 |
| | | $amout = empty($sqlParam[':rate_level']) ? "ROUND(o.settlement_amount_sum * a.rate_level_1, 2) AS settlement_amount_sum, ROUND(o.settled_amount_sum * a.rate_level_1, 2) AS settled_amount_sum" |
| | | : "ROUND(o.settlement_amount_sum * (:rate_level+0), 2) AS settlement_amount_sum, ROUND(o.settled_amount_sum * (:rate_level+0), 2) AS settled_amount_sum"; |
| | | $sql = "SELECT o.date, o.order_count, o.settlement_amount_sum + O.settled_amount_sum AS amount_sum, 0 AS refund_order, 0.00 AS refund_amount_sum,".$amout. |
| | | " FROM (SELECT *, FROM_UNIXTIME(createtime, '%Y年%m月') AS date, |
| | | count(orderid) AS order_count, |
| | | SUM(CASE WHEN settlement_state = 0 THEN amount ELSE 0 END) AS settlement_amount_sum, |
| | | SUM(CASE WHEN settlement_state = 1 THEN amount ELSE 0 END) AS settled_amount_sum |
| | | FROM ims_site_store_order |
| | | WHERE buyerid IN (SELECT uid FROM ims_users WHERE invitation_code = :invitationCode) AND type = 3 |
| | | ORDER BY date) AS o |
| | | LEFT JOIN ims_agent a ON invitation_code = :invitationCode |
| | | WHERE o.date IS NOT NULL ORDER BY o.createtime DESC"; |
| | | $result = array(); |
| | | // 分页查询 |
| | | $result['count'] = count(pdo_fetchall($sql,$sqlParam)); |
| | | $result['list'] = pdo_fetchall($sql.' limit '.$param['firstRow'].",".$param['listRows'],$sqlParam); |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | public function getUserOrderDetail($param) { |
| | | if (!empty($param['uuid'])) { |
| | | $invitationCode = pdo_getcolumn('agent', array('uuid' => $param['uuid']), 'invitation_code', 1); |
| | | $sqlParam = array(':invitationCode' => $invitationCode); |
| | | $rate_level = pdo_getcolumn('agent', array('invitation_code' => $param['invitationCode']), 'rate_level_2', 1); |
| | | $sqlParam[':rate_level'] = $rate_level; |
| | | } else { |
| | | $sqlParam = array(':invitationCode' => $param["invitationCode"]); |
| | | } |
| | | // 自己的场合,使用rate_level_1,下级代理商的场合,使用rate_level_2 |
| | | $amout = empty($sqlParam[':rate_level']) ? "ROUND(o.amount * a.rate_level_1, 2) AS rate_amount," : "ROUND(o.amount * (:rate_level+0), 2) AS rate_amount,"; |
| | | $sqlParam[':date'] = $param["date"]; |
| | | $sql = "SELECT |
| | | o.orderid, |
| | | FROM_UNIXTIME(o.createtime,'%Y-%m-%d %H:%i:%S') AS createtime, |
| | | g.title, |
| | | o.buyer, |
| | | o.amount, |
| | | 0 AS refund_amount,".$amout. |
| | | "CASE WHEN o.settlement_state = 1 THEN '已结算' WHEN o.type = 3 THEN '待结算' END AS settlement_state, |
| | | CASE WHEN o.type = 1 THEN '待付款' WHEN o.type = 3 THEN '交易成功' END AS order_state |
| | | FROM ims_site_store_order o |
| | | LEFT JOIN ims_site_store_goods g ON g.id = o.goodsid |
| | | LEFT JOIN ims_agent a ON invitation_code = :invitationCode |
| | | WHERE |
| | | o.buyerid IN (SELECT uid FROM ims_users WHERE invitation_code = :invitationCode) |
| | | AND FROM_UNIXTIME(o.createtime, '%Y年%m月') = :date AND o.type != 2 "; |
| | | |
| | | // 检索条件 |
| | | if (!empty($param['orderid'])) { |
| | | $sql .= " AND o.orderid LIKE '%".$param["orderid"]."%' "; |
| | | } |
| | | if (!empty($param['buyer'])) { |
| | | $sql .= " AND o.buyer LIKE '%".$param["buyer"]."%' "; |
| | | } |
| | | if ($param['settlement_state'] != null && $param['settlement_state'] != '') { |
| | | $sql .= " AND o.settlement_state = :settlement_state "; |
| | | $sqlParam[':settlement_state'] = $param['settlement_state']; |
| | | } |
| | | if ($param['order_state'] != null && $param['order_state'] != '') { |
| | | $sql .= " AND o.type = :order_state "; |
| | | $sqlParam[':order_state'] = $param['order_state']; |
| | | } |
| | | $sql .=" ORDER BY o.createtime DESC"; |
| | | |
| | | $result = array(); |
| | | // 分页查询 |
| | | $result['count'] = count(pdo_fetchall($sql,$sqlParam)); |
| | | $result['list'] = pdo_fetchall($sql.' limit '.$param['firstRow'].",".$param['listRows'],$sqlParam); |
| | | return $result; |
| | | } |
| | | |
| | | public function getAgentList($param) { |
| | | if (!empty($param['uuid'])) { |
| | | $invitationCode = pdo_getcolumn('agent', array('uuid' => $param['uuid']), 'invitation_code', 1); |
| | | $sqlParam = array(':invitationCode' => $invitationCode); |
| | | } else { |
| | | $sqlParam = array(':invitationCode' => $param["invitationCode"]); |
| | | } |
| | | // 获取我的代理商,已结算金额 和 待结算金额 |
| | | $sql = "SELECT |
| | | sub.uuid, |
| | | sub.agent_code, |
| | | sub.agent_name, |
| | | sub.invitation_code, |
| | | sub.create_date, |
| | | ROUND(SUM(CASE WHEN o.type = 1 THEN o.amount ELSE 0 END) * p.rate_level_2, 2) AS settlement_amount_sum, |
| | | ROUND(SUM(CASE WHEN o.type = 3 THEN o.amount ELSE 0 END) * p.rate_level_2, 2) AS settled_amount_sum |
| | | FROM ims_agent AS sub |
| | | LEFT JOIN ims_agent AS p on p.invitation_code = :invitationCode |
| | | LEFT JOIN ims_site_store_order o on o.buyerid IN (SELECT uid FROM ims_users WHERE invitation_code = sub.invitation_code) |
| | | WHERE |
| | | sub.parent_id = ( |
| | | SELECT |
| | | id |
| | | FROM |
| | | ims_agent |
| | | WHERE |
| | | invitation_code = :invitationCode |
| | | ) AND sub.uuid IS NOT NULL GROUP BY sub.agent_code "; |
| | | $result = array(); |
| | | $listAll = pdo_fetchall($sql,$sqlParam); |
| | | // 已结算金额合计 和 待结算金额合计 |
| | | for ($i = 0;$i < count($listAll);$i++) { |
| | | $settlement_amount_total += $listAll[$i]['settlement_amount_sum']; |
| | | $settled_amount_total += $listAll[$i]['settled_amount_sum']; |
| | | } |
| | | $result['settlement_amount_total'] = $settlement_amount_total; |
| | | $result['settled_amount_total'] = $settled_amount_total; |
| | | // 分页查询 |
| | | $result['count'] = count($listAll); |
| | | $result['list'] = pdo_fetchall($sql.' limit '.$param['firstRow'].",".$param['listRows'],$sqlParam); |
| | | return $result; |
| | | } |
| | | } |