1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\model\concern\SoftDelete;
- class OrderCategory extends Model{
- use SoftDelete;
- protected $createTime = 'createTime';
- protected $deleteTime='delete_time';
- public function GoodInfo(){
- return $this->belongsTo(Good::class,"spuCode","spuCode")->bind(["good_name"]);
- }
- public static function checkInfo($code,$orderType,$info){
- if(!empty($info)){
- $save=[];
- foreach ($info as $key=>$value){
- $ist = self::where(["code"=>$code,"order_type"=>$orderType,"spuCode"=>$value['spuCode']])->findOrEmpty();
- if($ist->isEmpty() || $ist->cat_code==''){
- $Temp=[
- "id"=>$ist->id??null,
- "code"=>$code,
- "order_type"=>$orderType,
- "spuCode"=>$value['spuCode'],
- "cat_code"=>$value['cat_code']??"",
- "cat_name"=>$value['cat_name']??"",
- "short_name"=>$value['short_name']??"",
- "merge_code"=>$value['merge_code']??"",
- "tax"=>$value['tax']??"",
- "inv_good_name"=>$value['inv_good_name']
- ];
- $save[]=$Temp;
- }
- }
- if(!empty($save)){
- (new OrderCategory)->saveAll($save);
- }
- }
- }
- public static function GetTaxInfoByCode($code){
- $info=self::with(['GoodInfo'])->where(["code"=>$code])->field(["code","spuCode","cat_code","cat_name","merge_code","short_name","tax","inv_good_name"])->select();
- $temp=[];
- if(!empty($info)){
- if (is_array($code)){
- foreach ($info as $value){
- $temp[$value['code']][]=$value;
- }
- }else $temp= $info->toArray();
- }
- return $temp;
- }
- }
|