/**
* 改变一个订单的状态为指定值 zdh:TODO::
* @param 对象类型 $app 注入调用的对象
* @param 字符串 $order_id 订单号
* @param 整型 $status 订单变更为的状态
* @return 0/1 更改状态是否成功
*/
public function orderStatusChange($app, $order_id, $status)
{
$conditons = "order_id = :order_id:";
$parameters = [
"order_id" => $order_id
];
$order = Order::findFirst([
$conditons,
'bind' => $parameters
]);
if($order){
$order->status = $status;
$rs = $order->save();
if($rs){
return 1;
}else{
return 0;
}
}else{
return 0;
}
}
/**
* 用于买手查看任务,可按不同条件查看任务 zdh:TODO::
* @param [type] $app [description]
* @param [type] $mt [description]
* @param [type] $responseObj [description]
* @return 任务列表
*/
public function orderTaskList($app, $mt, $responseObj)
{
$nt = strtotime(date("Y-m-d H:i:s"));
$allt = 7200;
$uid = $app->request->getPost("uid");
$page = $app->request->getPost("page");
$sort_group = $app->request->getPost("sort_group");
$sort_num = $app->request->getPost("sort_num");
$sort_time = $app->request->getPost("sort_time");
$sp = ($page - 1) * 10;
//0:所有人;1:自己;2:粉丝;3:其他
$sqlbid = "";
$sqlpx = "";
if($sort_group == 0){
$sqlbid = "";
}
if($sort_group == 1){
$sqlbid = "and [Order].uid=".$uid;
}
if($sort_group == 2){
$sqlbid = "and [Order].uid in (select fans_id from Fans where focus_id=".$uid.")";
}
if($sort_group == 3){
$sqlbid = "and [Order].uid!=".$uid." and [Order].uid not in (select fans_id from Fans where focus_id=".$uid.")";
}
//sort_num:(0:默认;1:由多到少;2:由少到多)默认为0
//sort_time:(0:默认;1:由多到少;2:由少到多)默认为0
if($sort_num == 0 && $sort_time == 0){
$sqlpx = "";
}
if($sort_num == 1 && $sort_time == 0){
$sqlpx = "order by count(OrderGoods.order_id) desc";
}
if($sort_num == 2 && $sort_time == 0){
$sqlpx = "order by count(OrderGoods.order_id) asc";
}
if($sort_time == 1 && $sort_num == 0){
$sqlpx = "order by [Order].order_start_time desc";
}
if($sort_time == 2 && $sort_num == 0){
$sqlpx = "order by [Order].order_start_time asc";
}
if($sort_num == 1 && $sort_time == 1){
$sqlpx = "order by count(OrderGoods.order_id) desc,[Order].order_start_time desc";
}
if($sort_num == 1 && $sort_time == 2){
$sqlpx = "order by count(OrderGoods.order_id) desc,[Order].order_start_time asc";
}
if($sort_num == 2 && $sort_time == 1){
$sqlpx = "order by count(OrderGoods.order_id) asc,[Order].order_start_time desc";
}
if($sort_num == 2 && $sort_time == 2){
$sqlpx = "order by count(OrderGoods.order_id) asc,[Order].order_start_time asc";
}
$phql = "SELECT
[Order].order_id,
[Order].order_start_time as starttime,
User.user_name as usr_name,
User.user_portrait as avatar,
Address.code_id as address,
[Order].uid as buyer_id,
sum(Goods.dis_price_rmb*OrderGoods.num) as total_price,
count(OrderGoods.order_id) as task_num
from
[Order], User, Address, OrderGoods, Goods
where
[Order].status in (1, 2)
and [Order].order_id=OrderGoods.order_id
and OrderGoods.goods_id=Goods.goods_id
and [Order].uid=User.user_uid
and [Order].address_id=Address.address_id ".$sqlbid."
group by [Order].order_id ".$sqlpx." limit ".$sp.", 10";
$sqlrc = "select count(*) as rc from [Order] where [Order].status in (1, 2) ".$sqlbid;
$rows = $app->modelsManager->executeQuery($phql);
$rc = $app->modelsManager->executeQuery($sqlrc)->getFirst()->rc;
if($rc % 10 == 0){
$pagecount = $rc / 10;
}else{
$pagecount = (int)($rc / 10) + 1;
}
$tasks = array();
$i = 0;
foreach ($rows as $row) {
$rel = 0;
$phql = "select * from Fans where fans_id=".$row->buyer_id." and focus_id=".$uid;
$rsfs = $app->modelsManager->executeQuery($phql);
$rsf = $rsfs->getFirst();
if($row->buyer_id == $uid)
{
$rel = 0;
}else{
if(empty($rsf)){
$rel = 3;//bu shi fans
}else{
$rel = 1;//shi fans
}
}
$phql = "select fid,name from Addr where id=".$row->address;
$rsq = $app->modelsManager->executeQuery($phql)->getFirst();
$qfid = $rsq->fid;
$qname = $rsq->name;
$phql = "select name from Addr where id=".$qfid;
$fname = $app->modelsManager->executeQuery($phql)->getFirst()->name;
if($fname."市" == $qname){
$qsname = $qname;
}else {
$qsname = $fname."市,".$qname;
}
$tj['order_id'] = $row->order_id;
$tj['avatar'] = $row->avatar;
$tj['usr_name'] = $row->usr_name;
$tj['relative'] = (string)$rel;
$tj['address'] = $qsname;
$tj['task_num'] = $row->task_num;
$tj['total_price'] = $row->total_price;
$tj['order_time'] = (string)($allt - ($nt - strtotime($row->starttime)));
$tasks[$i] = $tj;
$i ++;
}
//构建输出对象
$responseObj['data']['pagecount'] = (string)$pagecount;
$responseObj['data']['currentpage'] = $page;
$responseObj['data']['data'] = $tasks;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
/**
* 对指定订单进行软删除 zdh:TODO::
* @param [type] $app [description]
* @param [type] $mt [description]
* @param [type] $responseObj [description]
* @return 0/1 标定删除是否成功
*/
public function orderDelete($app, $mt, $responseObj)
{
$success = "0";
$order_id = $app->request->getPost("order_id");
$conditons = "order_id = :order_id:";
$parameters = [
"order_id" => $order_id
];
$order = Order::findFirst([
$conditons,
'bind' => $parameters
]);
if($order){
$order->isdel = 1;
$rs = $order->save();
if($rs){
$success = "1";
}else{
$success = "0";
}
}else{
$success = "0";
}
//构建输出对象
$responseObj['data']['success'] = $success;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
/**
* 上传图片 zdh:TODO::
* @param 对象类型 $app 注入调用的对象
* @param 时间戳 $mt 用来计算运行时间的变量
* @return 0/1 标定操作是否成功
*/
public function uploadImg($app, $mt, $upload_path, $responseObj)
{
$buyer_id = $app->request->getPost("buyer_id");
$order_id = $app->request->getPost("order_id");
$error = 0;
$success = "0";
if ($this->request->hasFiles() == true) {
if(is_dir("images/".$buyer_id."/")){
}else {
mkdir($upload_path.$buyer_id."/");
chmod($upload_path.$buyer_id."/",0777);
}
foreach ($this->request->getUploadedFiles() as $file) {
try {
$file->moveTo($upload_path.$buyer_id."/".$file->getName());
$orderimg = new Orderimg();
$orderimg->id = null;
$orderimg->order_id = $order_id;
$orderimg->img = $buyer_id."/".$file->getName();
$rs = $orderimg->save();
if(!$rs){
$error ++;
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
if($error == 0){
$success = "1";
}else{
$success = "0";
}
//构建输出对象
$responseObj['data']['success'] = $success;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
/**
* 上传物流单号 zdh:TODO::
* @param 对象类型 $app 注入调用的对象
* @param 时间戳 $mt 用来计算运行时间的变量
* @return 0/1 标定操作是否成功
*/
public function uploadLogistics($app, $mt, $responseObj)
{
$order_id = $app->request->getPost("order_id");
$logistics = $app->request->getPost("logistics");
$logisticsname = $app->request->getPost("logisticsname");
$success = "0";
$conditons = "order_id = :order_id:";
$parameters = [
"order_id" => $order_id
];
$order = Order::findFirst([
$conditons,
'bind' => $parameters
]);
if($order){
$order->status = 5;
$order->wuliu_no = $logistics;
$order->wuliu_company = $logisticsname;
$rs = $order->save();
if ($rs) {
$success = "1";//更新成功
}else {
$success = "0";//更新失败
}
}else {
$success = "0";//更新失败
}
//构建输出对象
$responseObj['data']['success'] = $success;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
/**
* 订单取消 zdh:TODO::
* @param 对象类型 $app 注入调用的对象
* @param 时间戳 $mt 用来计算运行时间的变量
* @return 0/1 标定操作是否成功
*/
public function orderCancel($app, $mt, $responseObj)
{
$order_id = $app->request->getPost("order_id");
$cancel = $app->request->getPost("cancel");
$success = (string)$this->orderStatusChange($app, $order_id, $cancel);
//构建输出对象
$responseObj['data']['success'] = $success;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
/**
* 订单确认完成收到货了 zdh:TODO::
* @param 对象类型 $app 注入调用的对象
* @param 时间戳 $mt 用来计算运行时间的变量
* @return 0/1 标定操作是否成功
*/
public function orderSureFinish($app, $mt, $responseObj)
{
$order_id = $app->request->getPost("order_id");
$success = (string)$this->orderStatusChange($app, $order_id, 6);
//构建输出对象
$responseObj['data']['success'] = $success;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
/**
* 记录订单评价 zdh:TODO::
* @param 对象类型 $app 注入调用的对象
* @param 时间戳 $mt 用来计算运行时间的变量
* @return 0/1 标定操作是否成功
*/
public function orderJudge($app, $mt, $responseObj)
{
$order_id = $app->request->getPost("order_id");
$judge = $app->request->getPost("judge");
$success = "0";
$conditons = "order_id = :order_id: and status = 3";
$parameters = [
"order_id" => $order_id
];
$plan = Plan::findFirst([
$conditons,
'bind' => $parameters
]);
if($plan){
$plan->judge_star = $judge;
$rs = $plan->save();
if($rs){
$success = "1";
}else{
$success = "0";
}
}else{
$success = "0";
}
//构建输出对象
$responseObj['data']['success'] = $success;
$responseObj['timeSpend'] = microtime() - $mt.'ms';
return $responseObj;
}
相关文章推荐: