ZaActivityRelation.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\api\model\za;
  4. use app\common\model\Goods;
  5. use app\common\model\GoodsSku;
  6. use app\common\model\BaseModel;
  7. use app\common\model\UploadFile;
  8. use app\common\model\za\ZaActivityRelation as ZaActivityRelationModel;
  9. /**
  10. * 活动中心 ▸买一赠一活动 关联数据
  11. * Class Ad
  12. * @package app\common\model
  13. */
  14. class ZaActivityRelation extends ZaActivityRelationModel
  15. {
  16. protected $name = 'za_activity_relations';
  17. // protected $append = ['image'];
  18. // public function getImageAttr(){
  19. // $a = UploadFile::field('file_id,file_type,storage,domain,file_path')->find($this->image_id)->external_url??'';
  20. // return $a;
  21. // }
  22. // public function file(){
  23. // return $this->hasOne('app\common\model\UploadFile', 'file_id', 'image_id');
  24. // }
  25. /**
  26. * 一对多关联商品表
  27. */
  28. public function activity(){
  29. return $this->belongsTo('ZaActivity', 'id','za_activity_id');
  30. }
  31. // public function add($activity_id, $data){
  32. // // 先删除全部
  33. // static::deleteAll(['ms_activity_id' => $activity_id]);
  34. // if (!empty($data)) {
  35. // // 添加
  36. // $dataset = [];
  37. // foreach ($data as $item) {
  38. // // 商品信息
  39. // // $goodsInfo = Goods::detail($item['goods_id']);
  40. // // if (empty($goodsInfo)) {
  41. // // $this->error = "商品信息错误";
  42. // // return false;
  43. // // }
  44. // $goods = Goods::where("goods_no",$item['goods_sku_no'])->find();
  45. // if (empty($goods)) {
  46. // $this->error = "图片skuno错误";
  47. // return false;
  48. // }
  49. // $dataset[] = [
  50. // 'ms_activity_id' => $activity_id,
  51. // 'goods_id' => $goods['goods_id'],
  52. // 'image_id'=>$item['image_id'],
  53. // 'goods_sku_no'=>$item['goods_sku_no']
  54. // ];
  55. // }
  56. // (new static)->addAll($dataset);
  57. // return true;
  58. // }
  59. // }
  60. }