25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Test.php 1.7 KiB

3 년 전
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace common\models;
  3. use yii\base\Exception;
  4. use Yii;
  5. use fx\util\FxUtil;
  6. /**
  7. * This is the model class for table "order_main".
  8. *
  9. * @property integer $id
  10. * @property string $name
  11. */
  12. class Test extends \yii\db\ActiveRecord
  13. {
  14. /**
  15. * @inheritdoc
  16. */
  17. public static function tableName()
  18. {
  19. return 'fx_user';
  20. }
  21. public function testList(){
  22. $select = [
  23. 'uid',
  24. new Expression("ifnull(user_name,'') as user_name") ,
  25. 'phone',
  26. 'nickname'
  27. ];
  28. $list=self::find()->select($select)
  29. ->limit(100)
  30. ->asArray(true)
  31. ->all();
  32. return $list;
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['id'], 'number'],
  41. [['name'], 'string', 'max' => 255],
  42. ];
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'Order ID',
  51. 'name' => 'Spider Order ID',
  52. ];
  53. }
  54. /**
  55. * Function Description:插入主订单
  56. * Function Name: insertOrder
  57. *
  58. * @return bool
  59. *
  60. * @author 娄梦宁
  61. */
  62. public function insertOrder(){
  63. $values=[
  64. 'name'=>'3333',
  65. ];
  66. $transaction=Yii::$app->db->beginTransaction();
  67. try{
  68. $this->attributes=$values;
  69. $res=$this->insert(true);
  70. if(!$res){
  71. throw new Exception('添加出错');
  72. }
  73. $transaction->commit();
  74. return true;
  75. }catch (Exception $e){
  76. $transaction->rollBack();
  77. return false;
  78. }
  79. }
  80. }