链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. class ImsCjdcOrderMain extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. protected $table = 'ims_cjdc_order_main';
  10. public $timestamps = false;
  11. public function imsCjdcUser()
  12. {
  13. return $this->hasOne('\App\Models\ImsCjdcUser','id','user_id');
  14. }
  15. public function market()
  16. {
  17. return $this->hasOne('\App\Models\ImsCjdcMarket','id','market_id');
  18. }
  19. /**
  20. * 同时变更主订单和子订单状态,
  21. * @param $oid //主订单id
  22. * @param $state //订单状态
  23. */
  24. public function modifyState($oid,$state)
  25. {
  26. return DB::transaction(function () use ($oid,$state){
  27. $data1['state'] = $data2['state'] = $state;
  28. $data1['update_time'] = time();
  29. if ($state == 4) {
  30. $data1['complete_time'] = $data2['complete_time'] = time();
  31. } elseif ($state == 3) {
  32. $data1['jd_time'] = $data2['jd_time'] = time();
  33. }
  34. DB::table('ims_cjdc_order_main')
  35. ->where('id',$oid)
  36. ->update($data1);
  37. DB::table('ims_cjdc_order')
  38. ->where('order_main_id',$oid)
  39. ->update($data2);
  40. if ($state==4){
  41. //添加店铺流水记录
  42. $account = new StoreAccount();
  43. $account->addStoreAccount($oid);
  44. }
  45. return true;
  46. });
  47. }
  48. }