执行三级分销语句

执行三级分销语句


namespace app\modules\common\models;

use app\models\Order;

use app\models\User;

class CommissionForm extends CommonModel

{

    public $order_id;

    public $type;

    /**

     * 执行分佣

     */
    Public function comply()
    {
        if(!$type){
            $order = Order::find()->where(['id'=>$this->order_id])->one();
            $user_1 = $order->parent_id;
            $user_2 = $order->parent_id_1;
            $user_3 = $order->parent_id_2;
            $price_1 = $order->first_price;
            $price_2 = $order->second_price;
            $price_3 = $order->third_price;

            for($i=1; $i<4; $i++){
                $user_id = ${"user_$i"};
                $price = ${"price_$i"};
                if($user_id){
                    $user = User::find()->where(['id' => $user_id])->one();
                    if($user){
                        if($price > 0){
                            $money = $user->price + $price;
                            User::updateAll(['price' => $money], ['id' => $user_id]);
                        }
                    }
                }
            }

            // $order->is_price = 1;
             Order::updateAll( ['is_price' => 1],['id' =>$this->order_id]);


        }

        return ['code'=>0, 'msg'=>'success'];
    }

}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页