WeappAPI.php 5.88 KB
<?php
/**
 * Created by PhpStorm.
 * User: wxd1061
 * Date: 2018-10-29
 * Time: 17:34
 */

namespace app\home\controller;

use think\Exception;
use think\Session;
use think\Controller;
use think\Verify;
use think\Cookie;
use think\Page;
use think\Db;

class WeappAPI extends Controller
{
    public function _initialize()
    {
        Session::start();
    }

    //-----生成单-----
    public function create_order(){

       $db=Db::connect('mysql://test_mshop:test_mshop.123@172.16.8.211:3306/wxdxinshop#utf8');
       //接收数组
       $data=$_POST['data'];
       mlog($data,"create_order/");

       $data=json_decode($data,true);
       $stoid=$data[0]['store_id'];

       $sh=tpCache('shop_info',$stoid );

       mlog(json_encode($data),"create_order/".$stoid);

       $parentno="";
       if(count($data)>0)  $parentno=$sh['ERPId'] . date('ymdHis') . get_total_millisecond() . rand(1000, 9999);

       //数组是循环的
       foreach ($data as $k=>$v){
           $order_sn = $sh['ERPId'] . date('YmdHis') . get_total_millisecond(). rand(1000, 9999);
           if(empty($order_sn)) $parentno=$order_sn;
           $da = array(
               'order_sn' => $order_sn, // 订单编号
               'parent_sn' => $parentno, // 组合订单编号
               'user_id' => $v['user_id'], // 用户id
               'consignee' => $v['consignee'], // 收货人
               'province' => $v['province'],//'省份id',
               'city' => $v['city'],//'城市id',
               'district' => $v['district'],//'县',
               'twon' => $v['twon'],// '街道',
               'address' => $v['address'],//'详细地址',
               'more_address' => $v['more_address'],//'详细地址',
               'mobile' => $v['mobile'],//'手机',
               'zipcode' => $v['zipcode'],//'邮编',
               'email' => $v['email'],//'邮箱',
               'shipping_code' => $v['shipping_code'],//'物流编号',
               'shipping_name' => $v['shipping_name'], //'物流名称',
               'goods_price' => $v['goods_price'],//'商品价格',
               'shipping_price' => $v['shipping_price'],//'物流价格',
               'user_money' => $v['user_money'],//'使用余额',
               //'coupon_price' => $data['couponFee'],//'使用优惠券',
               //'coupon_no' => $data['coupon_id'],
               //'integral' => $data['pointsFee'], //'使用积分
               //'integral_money' => $data['pointsFee'],//使用积分+钱 的钱的那一部分
               'total_amount' => $v['total_amount'],// 订单总额
               'order_amount' => $v['order_amount'],//'应付款金额',
               'add_time' =>microtime_float(), // 下单时间
               'user_note' => $v['user_note'], // 用户下单备注
               'store_id' => $v['store_id'], // 门店ID
               'pickup_id' => $v['pickup_id'], // 门店ID
               'exp_type' => $v['exptype'], // 配送方式
           );

           mlog("1","create_order/".$stoid);

           $data['order_id'] = $order_id = $db->name("wxd_order")->insertGetId($da);
           if (!$order_id)
               return json(array('status' => -8, 'msg' => '添加订单失败', 'result' => NULL));

           mlog("2","create_order/".$stoid);
           // 记录订单操作日志
           $action_info = array(
               'order_id' => $order_id,
               'action_user' => $v['user_id'],
               'action_note' => '您提交了订单,请等待系统确认',
               'status_desc' => '提交订单', //''
               'log_time' => time(),
               'store_id' => $stoid,
           );

           mlog("3","create_order/".$stoid);

           $ut=null;
           $db->name('wxd_order_action')->insertGetId($action_info);
           $cartList = $v['order_goods'];
           foreach ($cartList as $key => $val) {
               $goods = M('goods')->where("goods_id", $val['goods_id'])->find();
               $data2['order_id'] = $order_id; // 订单id
               $data2['order_sn'] = $order_sn; // 订单编号
               $data2['goods_id'] = $val['goods_id']; // 商品id
               $data2['goods_name'] = $val['goods_name']; // 商品名称
               $data2['goods_sn'] = $val['goods_sn']; // 商品货号
               $data2['goods_num'] = $val['goods_num']; // 购买数量
               $data2['market_price'] = $val['market_price']; // 市场价
               $data2['goods_price'] = $val['goods_price']; // 商品价
               $data2['member_goods_price'] = $val['member_goods_price']; // 会员折扣价
               $data2['cost_price'] = $val['cost_price']; // 成本价
               $data2['store_id'] = $val['store_id']; //门店ID
               $order_goods_id =$db->name("wxd_order_goods")->insertGetId($data2);

               $data2['rec_id']=$order_goods_id;
               $data2=null;

           }
           mlog("4","create_order/".$stoid);
       }
       return   json(array('status' => 1, 'msg' => '提交订单成功', 'result' => $parentno)); // 返回新增的订单id
    }


    public function get_activity(){
		 $db=Db::connect('mysql://test_mshop:test_mshop.123@172.16.8.211:3306/wxdxinshop#utf8');
         $gid=I("gid");
         $prom_type=I("prom_type");
         $s= $db->name("wxd_activitylist")
             ->where("goods_listid",",".$gid.",")
             ->where("prom_type",$prom_type)
             ->where('is_end',0)
             ->where('is_show',1)
             ->find();
         if($s)
            return json(["code"=>0,"data"=>$s,""]);
         return json(['code'=>-1,"msg"=>"未找到活动"]);
    }

    //----获取商品购买数量----
    public function get_buy_good_num(){
         return json(["code"=>0,"data"=>['num'=>1]]);
    }

    //----获取商品活动购买数量----
    public function get_buy_prom_num(){
        $gid=I('goods_id');
        $gid=I('prom_type');
        return json(["code"=>0,"data"=>['num'=>1]]);
    }


}