| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <?php/** * Created by PhpStorm. * User: z-yang * Date: 2018/9/18 * Time: 18:30 */namespace App\Modules\Channel\Services;use App\Modules\Channel\Models\PayTemplate;class PayTemplateService{    /**     * 获取支付列表类型     * @param int $distribution_channel_id     * @return int     */    public static function getPayTemplate(int $distribution_channel_id){        $res = PayTemplate::where('distribution_channel_id',$distribution_channel_id)->select('product_template_type')->first();        $template_type = 2;        if($res){            return $template_type = $res->product_template_type;        }        if(in_array($template_type,[1,2])){            return $template_type;        }        return 2;    }    /**     * 更新或者设置类型     * @param int $distribution_channel_id     * @param int $type     * @return bool     */    public static function setPayTemplate(int $distribution_channel_id,int $type){        if(!in_array($type,[1,2])){            return false;        }        $res = PayTemplate::where('distribution_channel_id',$distribution_channel_id)->first();        if($res){            if($res->product_template_type == $type){                return false;            }            $res->product_template_type = $type;            $res->save();            return true;        }        PayTemplate::create([            'product_template_type'=>$type,            'distribution_channel_id'=>$distribution_channel_id        ]);        return true;    }}
 |