123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace app\admin\controller;
- use app\common\library\Common;
- use app\data\model\DataMerchants;
- use app\data\model\ShopOcean as Model;
- use app\data\model\DataUser;
- use Carbon\Carbon;
- use think\admin\Controller;
- use app\data\model\SystemUser;
- use think\admin\model\SystemConfig;
- use think\admin\service\AdminService;
- use think\db\Query;
- use think\facade\Db;
- use think\Request;
- /**
- * 海运订单管理
- * Class Xw
- * @package app\admin\controller\ShopOcean
- * http://www.zjnk.com/fileserver/News/04b7854f-bb0a-458b-b359-ce948acfea09.JPG
- */
- class ShopOcean extends Controller
- {
- /**
- * 列表
- * @auth true
- * @menu true
- */
- public function index(Request $request){
- if(AdminService::getUserId()==10000){
- $admin_id = [];
- }else{
- $admin_id['admin_id']=AdminService::getUserId();
- }
- $this->title='海运订单管理';
- $this->assign('status',\app\data\model\ShopPurchase::getStatus());
- $result = Model::mQuery()
- ->with(['merchant'])
- ->when($request['name'],function (Query $query)use ($request){
- $query->hasWhere('merchant',function (Query $query)use ($request){
- $query->whereLike('name',"%{$request['name']}%");
- });
- })->where($admin_id)
- ->equal('status')
- ->dateBetween('create_time');
- // ->layTable();
- $this->amount = $result->db()->sum('amount');
- $result->page();
- }
- /**
- * 详情
- * @auth true
- * @menu true
- */
- public function detail(Request $request,Model $purchase){
- DataUser::$copyRealName=true;
- $this->assign('row',$purchase
- ->with(['merchant','items','offers','offers.user'])
- ->where('id',$request['id'])->findOrFail());
- $this->fetch('form');
- }
- /**
- * 发布
- * @auth true
- * @menu true
- */
- public function add(Request $request,\think\Validate $validate){
- $this->title='发布订单';
- $this->assign('vo',null);
- if($request->isGet()) {
- $config = systemConfig('merchant_config.packing')?:[];
- $this->assign('config',$config);
- $this->fetch();
- }else{
- $merchant=DataMerchants::getByAdmin(AdminService::getUserId());
- if(!$merchant){
- $this->error('您不是商家无法发布');
- }
- $data=$request->post();
- $item=$data['item']??[];
- foreach ($item as $i){
- $make=$validate->check($i,[
- 'name'=>['require',],
- 'weight'=>['require','integer'],
- // 'spec'=>['require',],
- // 'number'=>['require','integer'],
- // 'standard'=>['require',],
- // 'price'=>['require','float'],
- ]);
- if(!$make){
- $this->error('请填写正确的商品信息');
- }
- }
- app()->db->startTrans();
- unset($data['item']);
- $data['admin_id']=AdminService::getUserId();
- $data['form']=implode(',',$data['fm']);
- $data['longitude']=$merchant['longitude']??null;
- $data['latitude']=$merchant['latitude']??null;
- // $data['amount']=min(array_column($item,'price'));
- $data['type'] =1;
- $order= \app\data\model\ShopOcean::create($data);
- $order->items()->saveAll($item);
- app()->db->commit();
- $this->success('保存成功');
- }
- }
- /**
- * 编辑
- * @auth true
- * @menu true
- */
- public function edit(Request $request,Model $purchase,\think\Validate $validate){
- // $this->title='发布订单';
- // $this->assign('vo',null);
- if($request->isGet()) {
- DataUser::$copyRealName=true;
- $config = systemConfig('merchant_config.packing')?:[];
- $this->assign('config',$config);
- $row = $purchase
- ->with(['merchant','items','offers','favourite','ppoffer'])
- ->where('id',$request['id'])->findOrFail();
- if (!$row['merchant']){
- $array = ['company'=>'平台发布'];
- $row['merchant'] = $array;
- }
- // var_dump($row['form']);die;
- $row['fm'] = explode(',',$row['form']);
- $this->assign('row',$row);
- $this->fetch('edit');
- }else{
- $merchant=DataMerchants::getByAdmin(AdminService::getUserId());
- if(!$merchant){
- $this->error('您不是商家无法发布');
- }
- $data=$request->post();
- $item=$data['item']??[];
- foreach ($item as $i){
- $make=$validate->check($i,[
- 'name'=>['require',],
- 'weight'=>['require','integer'],
- // 'spec'=>['require',],
- // 'number'=>['require','integer'],
- // 'standard'=>['require',],
- // 'price'=>['require','float'],
- ]);
- if(!$make){
- $this->error('请填写正确的商品信息');
- }
- }
- app()->db->startTrans();
- unset($data['item']);
- $data['admin_id']=AdminService::getUserId();
- $data['form']=implode(',',$data['fm']);
- $data['longitude']=$merchant['longitude']??null;
- $data['latitude']=$merchant['latitude']??null;
- // $data['amount']=min(array_column($item,'price'));
- $data['type'] =1;
- // $order= \app\data\model\ShopOcean::create($data);
- $order=Model::update($data);
- $order->items()->saveAll($item);
- app()->db->commit();
- $this->success('保存成功');
- }
- }
- /**
- * 取消订单
- * @auth true
- * @menu true
- */
- public function cancellation(Request $request, \app\data\model\ShopOcean $purchase){
- $purchase_=$purchase->where('id',$request['id'])->findOrFail();
- $purchase_['status']=0;
- $purchase_->save();
- $this->success('取消成功');
- }
- }
|