1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class MobileOrderSubAnchor extends Model
- {
- protected $autoWriteTimestamp=false;
- public function admin(){
- return $this->belongsTo(Admin::class,'sub_admin_id','id',[],'left');
- }
- public function mobileAnchor(){
- return $this->belongsTo(MobileAnchor::class,'sub_mobile_anchor_id','id',[],'left');
- }
- public static function sync(MobileOrder $mobileOrder,$mobileAnchorId){
- $admin=Admin::get($mobileOrder['s_id']);
- if(!$admin){
- return;
- }
- if($subAnchor=$mobileOrder->subAnchor()->where('sub_admin_id',$admin['id'])->find()){
- $subAnchor['sub_mobile_anchor_id']=$mobileAnchorId;
- $subAnchor->save();
- }else{
- $mobileOrder->subAnchor()->save([
- 'sub_admin_id'=>$admin['id'],
- 'sub_mobile_anchor_id'=>$mobileAnchorId,
- ]);
- }
- }
- }
|