MobileOrderSubAnchor.php 947 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class MobileOrderSubAnchor extends Model
  5. {
  6. protected $autoWriteTimestamp=false;
  7. public function admin(){
  8. return $this->belongsTo(Admin::class,'sub_admin_id','id',[],'left');
  9. }
  10. public function mobileAnchor(){
  11. return $this->belongsTo(MobileAnchor::class,'sub_mobile_anchor_id','id',[],'left');
  12. }
  13. public static function sync(MobileOrder $mobileOrder,$mobileAnchorId){
  14. $admin=Admin::get($mobileOrder['s_id']);
  15. if(!$admin){
  16. return;
  17. }
  18. if($subAnchor=$mobileOrder->subAnchor()->where('sub_admin_id',$admin['id'])->find()){
  19. $subAnchor['sub_mobile_anchor_id']=$mobileAnchorId;
  20. $subAnchor->save();
  21. }else{
  22. $mobileOrder->subAnchor()->save([
  23. 'sub_admin_id'=>$admin['id'],
  24. 'sub_mobile_anchor_id'=>$mobileAnchorId,
  25. ]);
  26. }
  27. }
  28. }