php客户订单自动录入,2、录入订单

编辑add方法:

~~~

public function add()

{

$activeuser = UserModel::where('status',1)->find();

$this->assign('activeuser', $activeuser['username']);

return $this->fetch();

}

~~~

模板文件:

/apps/index/view/order/add.html

~~~

{layout name="layout" /}

当前账户:{$activeuser}

上传

~~~

打开浏览器

http://127.0.0.1/tp5/public/index.php/index/order/add

页面输出类似

![](https://box.kancloud.cn/2016-07-28_579970f6eb1de.png)

上传订单报表

订单报表是CSV格式的外部文件

内容类似

~~~

"账期","分成用户nick","订单号","卖家NICK","订单金额","订购开始时间","订购结束时间","本月分摊金额","分成比例","合作方分成金额","备注

"

"201606","test222","107362570424","test22222","90.00","2016-06-20 00:00:00","2016-09-20 00:00:00","11.00","70%","7.70","null"

"201606","test222","307497150468","test2222234","15.00","2016-06-26 00:00:00","2016-09-26 00:00:00","0.83","70%","0.59","null"

"201606","test222","106388930044","test22222343","15.00","2016-04-07 00:00:00","2016-07-07 00:00:00","5.01","70%","3.51","null"

"201606","test222","105865170194","test222222","15.00","2016-03-06 00:00:00","2016-06-06 00:00:00","0.84","70%","0.59","null"

"201606","test222","106244970042","test2222245","15.00","2016-03-31 00:00:00","2016-06-30 00:00:00","4.84","70%","3.39","null"

~~~

编辑upload方法处理上传文件:

~~~

public function upload()

{

$file = request()->file('csv');

$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads','data.csv');

if($info){

$datasrc = array();

while($array = $file->fgetcsv()) {

$datasrc[] = $array;

}

$sum_record = count($datasrc);

if($sum_record > 1){

Cache::set('name',$datasrc,36000);

$this->redirect('http://127.0.0.1/tp5/public/index.php/index/order/save/step/1');

}

}else{

echo $file->getError();

}

}

~~~

编辑save方法保存订单:

~~~

public function save($step = 1)

{

$activeuser = UserModel::where('status',1)->find();

$tpl = TplModel::where(['uid'=> $activeuser['uid'],'ttype'=> 1])->find();

$datasrc = Cache::get('name');

$sum_data = count($datasrc);

$endpoint = min(($step+100),$sum_data);

if($step < $sum_data){

for($i=$step;$i

{

echo "STEP".$i." ";

if(is_numeric($datasrc[$i][2])){

$order = OrderModel::get(['uid'=> $activeuser['uid'],'ap'=>$datasrc[$i][0],'onum'=> $datasrc[$i][2]]);

if($order){

continue;

}else{

$neworder = new OrderModel;

$neworder->uid = $activeuser['uid'];

$neworder->ap = intval($datasrc[$i][0]);

$neworder->onum = $datasrc[$i][2];

$neworder->snick = $datasrc[$i][1];

$neworder->bnick = $datasrc[$i][3];

$neworder->stime = $datasrc[$i][5];

$neworder->etime = $datasrc[$i][6];

$neworder->oamount = floatval($datasrc[$i][4]);

if($tpl and $neworder->oamount >= 90){

$neworder->tid = $tpl['tid'];

}

$neworder->pamount = floatval($datasrc[$i][7]);

$neworder->damount = floatval($datasrc[$i][9]);

$neworder->trate = floatval($datasrc[$i][8])/100;

$neworder->remark = $datasrc[$i][10];

if($neworder->save()){

echo '订单'.$neworder->oid.'新增成功!';

}

}

}

}

$step = $step+100;

return $this->success('STEP'.$step,'http://127.0.0.1/tp5/public/index.php/index/order/save/step/'.$step,'',1);

}else{

return $this->success('录入成功','http://127.0.0.1/tp5/public/index.php/index/order/');

}

}

~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值