ShopGoods.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 $CATEGORY_TYPE 商品分类
  12. * @property string $SELL_TYPE 允许购买方式
  13. * @property int $GOODS_NO 商品编号
  14. * @property string $UNIT 单位
  15. * @property string $COVER 商品封面
  16. * @property int $IMAGES 商品图片
  17. * @property string $CONTENT 商品内容
  18. * @property string $SELL_PRICE_STANDARD 标准价格
  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. 'id' => 1,
  34. 'name' => 'Account Balance', //余额购买
  35. 'label' => 'cash',
  36. 'language' => 'shopListAccountBalance',
  37. ],
  38. // 2 => [
  39. // 'id' => 2,
  40. // 'name' => '复消兑换',
  41. // ],
  42. // 3 => [
  43. // 'id' => 3,
  44. // 'name' => '兑换点数',
  45. // 'label' => 'exchange',
  46. // ],
  47. 7 => [
  48. 'id' => 7,
  49. 'name' => 'PayStack',
  50. 'label' => 'pay_stack',
  51. 'language' => 'saleTypePayStack',
  52. ],
  53. 8 => [
  54. 'id' => 8,
  55. 'name' => 'Performance Bonus',
  56. 'label' => 'prp',
  57. 'language' => 'shopPayTypeUserPerformance',
  58. ],
  59. ];
  60. const GOODS_TYPE = [
  61. 1 =>[
  62. 'name'=>'国内商品',//国内商品
  63. 'discount'=>'50',
  64. 'language' => 'shopGoodTypeDomestic',
  65. ],
  66. 2 =>[
  67. 'name'=>'进口商品',//进口商品
  68. 'discount'=>'60',
  69. 'language' => 'shopGoodTypeImport',
  70. ],
  71. ];
  72. const GIFT_TYPE = [
  73. 1 =>[
  74. 'name'=>'1st Purchase',//报单区
  75. ],
  76. 2 =>[
  77. 'name'=>'Repeat Purchase',//复消区
  78. ],
  79. // 3 =>[
  80. // 'name'=>'Office Entry area',//工作室报单
  81. // ],
  82. // 4 =>[
  83. // 'name'=>'Office Reselling area',//工作室复消
  84. // ],
  85. ];
  86. const STATUS_NAME = [
  87. 1 => 'On sale',//已上架
  88. 0 => 'Sold out',//已下架
  89. ];
  90. const CATEGORY_TYPE = [
  91. [
  92. 'id' => 1,
  93. 'name' => 'Standard Products',//普通商品
  94. 'sell_type' => [
  95. self::SALE_TYPE[1],
  96. self::SALE_TYPE[8],
  97. self::SALE_TYPE[7],
  98. ]
  99. ],
  100. ];
  101. /**
  102. * @inheritdoc
  103. */
  104. public static function tableName()
  105. {
  106. return '{{%SHOP_GOODS}}';
  107. }
  108. /**
  109. * @inheritdoc
  110. */
  111. public function rules()
  112. {
  113. return [
  114. [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'GOODS_NO', 'PRICE_PV','STORE_NUMS', 'SELL_TYPE', 'CATEGORY_TYPE', 'SELL_PRICE_STANDARD'], 'required'],
  115. [['STORE_NUMS'], 'integer'],
  116. [['PRICE_PV','POINT', 'CATEGORY_TYPE' ,'SELL_PRICE_STANDARD'], 'number'],
  117. [['ID','CATE_ID', 'GOODS_NO','GIFT_TYPE'], 'string', 'max' => 32],
  118. [['UNIT'], 'string', 'max' => 16],
  119. [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
  120. [['IMAGES','CONTENT'], 'string', 'max' => 4000],
  121. [['GOODS_NAME'], 'unique'],
  122. [['ID'], 'unique'],
  123. ];
  124. }
  125. /**
  126. * @inheritdoc
  127. */
  128. public function attributeLabels()
  129. {
  130. return [
  131. 'ID' => 'ID',
  132. 'GOODS_NAME' => '商品名称',
  133. 'CATE_ID' => '所属分类ID',
  134. 'SELL_DISCOUNT' => '会员折扣',
  135. 'GIFT_TYPE' => '商品类型',
  136. 'CATEGORY_TYPE' => '商品分类',
  137. 'SELL_TYPE' => '出售方式',
  138. 'GOODS_NO' => '商品编号',
  139. 'UNIT' => '商品单位',
  140. 'COVER' => '商品封面',
  141. 'IMAGES' => '商品图片',
  142. 'CONTENT' => '商品内容',
  143. 'SELL_PRICE_STANDARD' => 'US price($)',
  144. 'PRICE_PV' => '价格PV',
  145. 'STORE_NUMS' => '库存',
  146. 'STATUS' => '是否上架',
  147. 'IS_DEL' => '是否删除',
  148. 'CREATED_AT' => '创建时间',
  149. 'UPDATED_AT' => '更新时间',
  150. 'DELETED_AT' => '更新时间',
  151. 'SORT' => '排序',
  152. ];
  153. }
  154. /**
  155. * 判断提现状态
  156. * @param $nowStatus
  157. * @param $toStatus
  158. * @return string
  159. */
  160. public static function chkAuditStatus($nowStatus, $toStatus) {
  161. $statusName = self::STATUS_NAME;
  162. $msg = \Yii::t('ctx', 'shopSetProductStatusErrorNotice', [
  163. 'nowStatus' => $statusName[$nowStatus],
  164. 'newStatus' => $statusName[$toStatus]
  165. ]);
  166. switch ($toStatus) {
  167. // 下架
  168. case 0:
  169. if ($nowStatus == 1) {
  170. $msg = '';
  171. }
  172. break;
  173. //上架
  174. case 1:
  175. if ($nowStatus == 0) {
  176. $msg = '';
  177. }
  178. break;
  179. default:
  180. }
  181. return $msg;
  182. }
  183. /**
  184. * 支付方式
  185. * @return array
  186. */
  187. public static function payTypes(){
  188. return [
  189. 'cash'=>[
  190. 'name'=> \Yii::t('ctx', 'shopPayTypeCash')//余额支付
  191. ],
  192. 'prp' => [
  193. 'name' => \Yii::t('ctx', 'shopPayTypeUserPerformance')
  194. ],
  195. 'pay_stack' => [
  196. 'name' => 'PayStack'
  197. ],
  198. ];
  199. }
  200. // 获取商品类型
  201. public static function getGiftType() {
  202. return [
  203. 1 =>[
  204. 'name'=>\Yii::t('ctx', 'shopList1stPurchase'),//报单区
  205. ],
  206. 2 =>[
  207. 'name'=>\Yii::t('ctx', 'shopListRepeatPurchase'),//复消区
  208. ],
  209. // 3 =>[
  210. // 'name'=>\Yii::t('ctx', 'shopListEntryArea'),//工作室报单
  211. // ],
  212. // 4 =>[
  213. // 'name'=>\Yii::t('ctx', 'shopListResellingArea'),//工作室复消
  214. // ],
  215. ];
  216. }
  217. // 获取分类类型
  218. public static function getCategoryType() {
  219. return [
  220. [
  221. 'id' => 1,
  222. 'name' => \Yii::t('ctx', 'shopListStandardProducts'),//普通商品
  223. 'sell_type' => [
  224. self::SALE_TYPE[1],
  225. self::SALE_TYPE[8],
  226. self::SALE_TYPE[7],
  227. ]
  228. ],
  229. ];
  230. }
  231. public static function getSaleType(): array
  232. {
  233. return array_map(function ($item) {
  234. $item['name'] = \Yii::t('ctx', $item['language']);
  235. return $item;
  236. }, self::SALE_TYPE);
  237. }
  238. public static function getGoodType(): array
  239. {
  240. return array_map(function ($item) {
  241. $item['name'] = \Yii::t('ctx', $item['language']);
  242. return $item;
  243. }, self::GOODS_TYPE);
  244. }
  245. }