ShopGoods.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace common\models;
  3. /**
  4. * This is the model class for table "{{%SHOP_GOODS}}".
  5. *
  6. * @property string $ID
  7. * @property string $GOODS_NAME 商品名称
  8. * @property string $CATE_ID 所属分类ID
  9. * @property string $TYPE 商品来源
  10. * @property string $GIFT_TYPE 商品类型
  11. * @property string $SELL_TYPE 允许购买方式
  12. * @property int $GOODS_NO 商品编号
  13. * @property string $UNIT 单位
  14. * @property string $COVER 商品封面
  15. * @property int $IMAGES 商品图片
  16. * @property string $CONTENT 商品内容
  17. * @property string $SELL_PRICE 销售价格
  18. * @property string $MARKET_PRICE 市场价格
  19. * @property int $PRICE_PV 价格PV
  20. * @property int $POINT 兑换积分
  21. * @property int $STORE_NUMS 库存
  22. * @property int $IS_DEL 是否删除
  23. * @property int $CREATED_AT 创建时间
  24. * @property int $UPDATED_AT 更新时间
  25. * @property int $DELETED_AT 删除时间
  26. * @property int $STATUS 状态
  27. * @property string $SORT 排序
  28. */
  29. class ShopGoods extends \common\components\ActiveRecord
  30. {
  31. const SALE_TYPE = [
  32. 1 => [
  33. 'name' => '余额购买',
  34. ],
  35. 2 => [
  36. 'name' => '积分兑换',
  37. ],
  38. ];
  39. const GOODS_TYPE = [
  40. 1 =>[
  41. 'name'=>'国内商品',
  42. 'discount'=>'50',
  43. ],
  44. 2 =>[
  45. 'name'=>'进口商品',
  46. 'discount'=>'60',
  47. ],
  48. ];
  49. const GIFT_TYPE = [
  50. 1 =>[
  51. 'name'=>'报单区',
  52. ],
  53. 2 =>[
  54. 'name'=>'复消区',
  55. ],
  56. 3 =>[
  57. 'name'=>'工作室报单',
  58. ],
  59. 4 =>[
  60. 'name'=>'工作室复消',
  61. ],
  62. ];
  63. const STATUS_NAME = [
  64. 1 => '已上架',
  65. 0 => '已下架',
  66. ];
  67. /**
  68. * @inheritdoc
  69. */
  70. public static function tableName()
  71. {
  72. return '{{%SHOP_GOODS}}';
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function rules()
  78. {
  79. return [
  80. [['GOODS_NAME', 'CATE_ID', 'TYPE','GIFT_TYPE', 'SELL_TYPE', 'GOODS_NO', 'SELL_PRICE','MARKET_PRICE','PRICE_PV','STORE_NUMS'], 'required'],
  81. [['TYPE','STORE_NUMS'], 'integer'],
  82. [['SELL_PRICE','MARKET_PRICE','PRICE_PV','POINT'], 'number'],
  83. [['ID','CATE_ID', 'GOODS_NO','SELL_TYPE','GIFT_TYPE'], 'string', 'max' => 32],
  84. [['UNIT'], 'string', 'max' => 16],
  85. [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
  86. [['IMAGES','CONTENT'], 'string', 'max' => 4000],
  87. [['GOODS_NAME'], 'unique'],
  88. [['ID'], 'unique'],
  89. ];
  90. }
  91. /**
  92. * @inheritdoc
  93. */
  94. public function attributeLabels()
  95. {
  96. return [
  97. 'ID' => 'ID',
  98. 'GOODS_NAME' => '商品名称',
  99. 'CATE_ID' => '所属分类ID',
  100. 'TYPE' => '商品来源',
  101. 'GIFT_TYPE' => '商品类型',
  102. 'SELL_TYPE' => '出售方式',
  103. 'GOODS_NO' => '商品编号',
  104. 'UNIT' => '商品单位',
  105. 'COVER' => '商品封面',
  106. 'IMAGES' => '商品图片',
  107. 'CONTENT' => '商品内容',
  108. 'SELL_PRICE' => '销售价格',
  109. 'MARKET_PRICE' => '市场价格',
  110. 'PRICE_PV' => '价格PV',
  111. 'POINT' => '兑换积分',
  112. 'STORE_NUMS' => '库存',
  113. 'STATUS' => '是否上架',
  114. 'IS_DEL' => '是否删除',
  115. 'CREATED_AT' => '创建时间',
  116. 'UPDATED_AT' => '更新时间',
  117. 'DELETED_AT' => '更新时间',
  118. 'SORT' => '排序',
  119. ];
  120. }
  121. /**
  122. * 判断提现状态
  123. * @param $nowStatus
  124. * @param $toStatus
  125. * @return string
  126. */
  127. public static function chkAuditStatus($nowStatus, $toStatus) {
  128. $statusName = self::STATUS_NAME;
  129. $msg = '当前商品状态为【' . $statusName[$nowStatus] . '】,无法设置为【' . $statusName[$toStatus] . '】';
  130. switch ($toStatus) {
  131. // 下架
  132. case 0:
  133. if ($nowStatus == 1) {
  134. $msg = '';
  135. }
  136. break;
  137. //上架
  138. case 1:
  139. if ($nowStatus == 0) {
  140. $msg = '';
  141. }
  142. break;
  143. default:
  144. }
  145. return $msg;
  146. }
  147. /**
  148. * 支付方式
  149. * @return array
  150. */
  151. public static function payTypes(){
  152. return [
  153. 'cash'=>[
  154. 'name'=>'余额支付'
  155. ],
  156. 'point'=>[
  157. 'name'=>'积分支付'
  158. ],
  159. ];
  160. }
  161. }